快速排序法的讲解
https://blog.youkuaiyun.com/qq_40941722/article/details/94396010
class Solution {
public:
string minNumber(vector<int>& nums) {
vector<string> strs;
for(int i = 0; i < nums.size(); i++)
strs.push_back(to_string(nums[i]));
quickSort(strs, 0, strs.size() - 1);
string res;
for(string s : strs)
res.append(s);
return res;
}
private:
void quickSort(vector<string>& strs, int l, int r) {
if(l >= r) return;//递归结束的标志
int i = l, j = r;
while(i < j) {
while(strs[j] + strs[l] >= strs[l] + strs[j] && i < j) j--;
while(strs[i] + strs[l] <= strs[l] + strs[i] && i < j) i++;
swap(strs[i], strs[j]);
}
swap(strs[i], strs[l]);
quickSort(strs, l, i - 1);//
quickSort(strs, i + 1, r);
}
};
//题思路总结:
//1.首先将数组nums的数依次存入字符串vector容器中。
//2.将字符串数组的数按照从“小”到“大”的顺序排列,自然而然想到快排法排列
//3.这里的大和小的定义为 若 x + y >= y + x , 则 x > y