标签:www 时间 solution 字典序 logs void ble 复杂度 wap
解法一:参见:http://www.cnblogs.com/grandyang/p/4428207.html 时间复杂度O(n)。
class Solution {
public:
void nextPermutation(vector<int>& nums) {
int n = nums.size(),i = n-2,j = n-1;
while(i >= 0 && nums[i] >= nums[i+1]) i--;
cout << i;
if(i >= 0)
{
while(nums[j] <= nums[i]) j--;
swap(nums[i],nums[j]);
}
reverse(nums.begin()+i+1,nums.end());
}
};
标签:www 时间 solution 字典序 logs void ble 复杂度 wap
原文地址:https://www.cnblogs.com/multhree/p/10383720.html