Skip to content

Commit

Permalink
Normalize mid calculate in case overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
rongyi committed May 14, 2024
1 parent 063a41f commit 44ddba3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn dfs(nums: &[i32], target: i32, i: i32, j: i32) -> i32 {
if i > j {
return -1;
}
let m: i32 = (i + j) / 2;
let m: i32 = i + (j - i) / 2;
if nums[m as usize] < target {
// 递归子问题 f(m+1, j)
return dfs(nums, target, m + 1, j);
Expand Down
4 changes: 1 addition & 3 deletions codes/rust/chapter_sorting/radix_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ fn counting_sort_digit(nums: &mut [i32], exp: i32) {
counter[d] -= 1; // 将 d 的数量减 1
}
// 使用结果覆盖原数组 nums
for i in 0..n {
nums[i] = res[i];
}
nums.copy_from_slice(&res);
}

/* 基数排序 */
Expand Down

0 comments on commit 44ddba3

Please sign in to comment.