Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Solution {
public:
void nextPermutation(vector<int>& nums) {
int i = nums.size() - 2;
while(i >= 0 && nums[i+1] <= nums[i])
i--;
if(i>=0){
int j = nums.size() - 1;
while(j >= i+1 && nums[j] <= nums[i])
j--;
swap(nums[i],nums[j]);
}
reverse(nums.begin()+i+1, nums.end());
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment