Next Permutation -- Math Problem
use 2 pointers:
- put first pointer
iat the second last position. - put second pt
jat the last position and judge if the val atjis greater than it is atido the while judge each time until the position ofj==i. - in each while iteration, judge if the val at
jis greater than it is ati. if so, break the inner while-loop, or j--. - if the inner while loop is done, then swap the var at
iandjand break the outer while loop. - reverse all elems from
i+1to the end;