Guest User

Untitled

a guest
Apr 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class Solution {
  5. public:
  6. void nextPermutation(vector<int>& nums) {
  7. int i = nums.size();
  8. while(i && nums[i - 1] >= nums[i])i--;
  9. if(i == 0){
  10. reverse(nums.begin(), nums.end());
  11. }
  12. swap(nums[i - 1], *upper_bound(nums.begin() + i, nums.end(), nums[i - 1]));
  13. }
  14. };
  15.  
  16. int main(){
  17. return 0;
  18. }
Add Comment
Please, Sign In to add comment