Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- class Solution {
- public:
- void nextPermutation(vector<int>& nums) {
- int i = nums.size();
- while(i && nums[i - 1] >= nums[i])i--;
- if(i == 0){
- reverse(nums.begin(), nums.end());
- }
- swap(nums[i - 1], *upper_bound(nums.begin() + i, nums.end(), nums[i - 1]));
- }
- };
- int main(){
- return 0;
- }
Add Comment
Please, Sign In to add comment