力扣-75题 颜色分类(C++)- 排序
作者:互联网
题目链接:https://leetcode-cn.com/problems/sort-colors/
题目如下:
class Solution {
public:
void sortColors(vector<int>& nums) {
quicksort(nums,0,nums.size()-1);
}
void quicksort(vector<int>& nums,int l,int r){
if(l>=r) return;
int i=l-1,j=r+1;
int target=nums[(i+j)>>1];
while(i<j){
do i++; while(nums[i]<target);
do j--; while(nums[j]>target);
if(i<j) swap(nums[i],nums[j]);
}
quicksort(nums,l,j);
quicksort(nums,j+1,r);
}
};
标签:target,nums,int,void,quicksort,while,C++,力扣,75 来源: https://blog.csdn.net/qq_40467670/article/details/122775806