zig : upgrade codes && rust : add codes for chapter_searching and chapter_dynamic_programming. (#591)

* zig : update zig codes

* rust : add codes for linear_search and hashing_search

* rust : add codes for linear_search and hashing_search

* rust : add codes for chapter_dynamic_programming
This commit is contained in:
sjinzh
2023-07-10 01:32:12 +08:00
committed by GitHub
parent 6c133d42d5
commit 459449d41a
21 changed files with 485 additions and 187 deletions
@@ -18,7 +18,7 @@ fn binarySearch(comptime T: type, nums: std.ArrayList(T), target: T) T {
} else if (nums.items[m] > target) { // 此情况说明 target 在区间 [i, m-1] 中
j = m - 1;
} else { // 找到目标元素,返回其索引
return @intCast(T, m);
return @intCast(m);
}
}
// 未找到目标元素,返回 -1
@@ -38,7 +38,7 @@ fn binarySearchLCRO(comptime T: type, nums: std.ArrayList(T), target: T) T {
} else if (nums.items[m] > target) { // 此情况说明 target 在区间 [i, m) 中
j = m;
} else { // 找到目标元素,返回其索引
return @intCast(T, m);
return @intCast(m);
}
}
// 未找到目标元素,返回 -1