mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-10 17:00:45 +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:
@ -36,7 +36,7 @@ void mergeSort(List<int> nums, int left, int right) {
|
||||
// 終止條件
|
||||
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