File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change
1
+ ## [ Generation in lexicographic order] ( http://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order )
1
2
2
- ## TODO
3
- * write down thinking
3
+ I can not work out this without Google's help.
4
4
5
+ steps below are copied from Wikipedia:
6
+
7
+ 1 . Find the largest index k such that a[ k] < a[ k + 1] . If no such index exists, the permutation is the last permutation.
8
+ 1 . Find the largest index l greater than k such that a[ k] < a[ l] .
9
+ 1 . Swap the value of a[ k] with that of a[ l] .
10
+ 1 . Reverse the sequence from a[ k + 1] up to and including the final element a[ n] .
11
+
12
+
13
+ [ Fisherlei's Image] ( http://fisherlei.blogspot.com/2012/12/leetcode-next-permutation.html ) is a good illustration.
14
+ You can see an image that how this solution goes.
You can’t perform that action at this time.
0 commit comments