Skip to content

Instantly share code, notes, and snippets.

@ws6
Created January 4, 2013 21:23
Show Gist options
  • Save ws6/4456178 to your computer and use it in GitHub Desktop.
Save ws6/4456178 to your computer and use it in GitHub Desktop.
next permutation
#include <algorithm>
class Solution {
public:
void nextPermutation(vector<int> &num) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector<int>::iterator first, last,i , j , k;
(); ();
if(first==last) return;
; i++;
if(i==last) return ;
; i--;
for(;;){
;
--i;
if(*i<*k){
;
while(!(*i<*--j)) ;
std::iter_swap(i,j);
std::reverse(k,last);
return ;
}
if(i==first){
std::reverse(first, last);
return;
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment