Next Permutation -- Math Problem
- put first pointer i at the second last position.
- put second pt j at the last position and judge if the val at j is greater than it is at i do the while judge each time until the position of j == i.
- in each While iteration, judge if the val at j is greater than it is at i. if so, break the inner while-loop, or j--.
- if the inner while loop is done, then swap the var at i and j and break the outer while loop.
- reverse all elems from i+1 to the end at the nums;
Top comments (0)