-
-
Notifications
You must be signed in to change notification settings - Fork 443
Open
Description
https://leetcode.com/problems/sort-an-array/
Modifying the code to the following version will pass the test
class Solution {
public int[] sortArray(int[] nums) {
quickSort(nums, 0, nums.length - 1);
return nums;
}
public static void quickSort(int[] arr, int left, int right) {
var pivotIndex = left + (right - left) / 2;
var pivotValue = arr[pivotIndex];
var i = left;
var j = right;
while (i <= j) {
while (arr[i] < pivotValue) {
i++;
}
while (arr[j] > pivotValue) {
j--;
}
if (i <= j) {
var tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
i++;
j--;
}
}
if (left < j) {
quickSort(arr, left, j);
}
if (right > i) {
quickSort(arr, i, right);
}
}
}
Metadata
Metadata
Assignees
Projects
Status
Todo