31.下一个排序
作者:互联网
class Solution {
public:
void nextPermutation(vector<int>& nums) {
int i, j;
if(nums.size() <= 1)
return;
for(i = nums.size()-2; i >= 0; i--){ //找左标记
if(nums[i] < nums[i + 1]){
break;
}
}
for(j = nums.size()-1; j > i && i != -1; j--){ //找右标记
if(nums[i] < nums[j]){
swap(nums[i], nums[j]);
break;
}
}
reverse(nums.begin() + i + 1, nums.end());
}
};
Accepted
265/265 cases passed (4 ms)
Your runtime beats 72.39 % of cpp submissions
Your memory usage beats 94.62 % of cpp submissions (11.6 MB)
标签:nums,一个,31,break,beats,265,排序,submissions,size 来源: https://blog.csdn.net/The_Dan/article/details/122024186