mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-06 14:27:26 +08:00
[Rust] Normalize mid calculation in case overflow (#1363)
* Normalize mid calculate in case overflow * Change ALL language * Update merge_sort.py * Update merge_sort.zig * Update binary_search_tree.zig * Update binary_search_recur.py --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@ -39,7 +39,7 @@ public class merge_sort {
|
||||
// 终止条件
|
||||
if (left >= right) return; // 当子数组长度为 1 时终止递归
|
||||
// 划分阶段
|
||||
int mid = (left + right) / 2; // 计算中点
|
||||
int mid = left + (right - left) / 2; // 计算中点
|
||||
MergeSort(nums, left, mid); // 递归左子数组
|
||||
MergeSort(nums, mid + 1, right); // 递归右子数组
|
||||
// 合并阶段
|
||||
|
Reference in New Issue
Block a user