class Solution {
public:
vector<int> sortArray(vector<int>& nums) {
srand(time(0));
quickSort(nums, 0, nums.size()-1);
return nums;
}
void quickSort(vector<int>& nums, int lo, int hi) {
if (lo >= hi) return;
int pivort_index = partition(nums, lo, hi);
quickSort(nums, lo, pivort_index - 1);
quickSort(nums, pivort_index + 1, hi);
}
int partition(vector<int>& nums, int lo, int hi) {
int rand_index = rand()%(hi-lo+1)+lo;
swap(nums[rand_index], nums[lo]);
int pivort = nums[lo];
int i = lo, j = hi;
while (i < j) {
while (i < j && nums[j] >= pivort)
--j;
nums[i] = nums[j];
while (i < j && nums[i] < pivort)
++i;
nums[j] = nums[i];
}
nums[i] = pivort;
return i;
}
};```