class Solution {

public:

void nextPermutation(vector<int>& nums) {

int idx;

for(idx = nums.size()-2; idx>=0; idx--){

if(nums[idx] < nums[idx+1])

break;

}

reverse(nums.begin()+idx+1, nums.end());

if(idx >= 0){

int i = idx;

while(nums[++i] <= nums[idx]);

swap(nums[i], nums[idx]);

}

}

};