Skip to content

Commit

Permalink
Update quick_sort.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
krahets authored Mar 14, 2024
1 parent 2e89598 commit 30d7e63
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions codes/typescript/chapter_sorting/quick_sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ class QuickSortMedian {
let l = nums[left],
m = nums[mid],
r = nums[right];
if ((l <= m && m <= r) || (r <= m && m <= l)) return mid; // m 在 l 和 r 之间
if ((m <= l && l <= r) || (r <= l && l <= m)) return left; // l 在 m 和 r 之间
// m 在 l 和 r 之间
if ((l <= m && m <= r) || (r <= m && m <= l)) return mid;
// l 在 m 和 r 之间
if ((m <= l && l <= r) || (r <= l && l <= m)) return left;
return right;
}

Expand Down

0 comments on commit 30d7e63

Please sign in to comment.