算法复习-全排列的非递归和递归实现(含重复元素)

from http://blog.csdn.net/so_geili/article/details/71078945

 

  1. Find the largest index k such that nums[k] < nums[k + 1]. If no such index exists, the permutation is sorted in descending order, just reverse it to ascending order and we are done. For example, the next permutation of [3, 2, 1] is [1, 2, 3].
  2. Find the largest index l greater than k such that nums[k] < nums[l].
  3. Swap the value of nums[k] with that of nums[l].
  4. Reverse the sequence from nums[k + 1] up to and including the final element nums[nums.size() - 1].

posted on 2017-12-20 12:34  mdumpling  阅读(161)  评论(0编辑  收藏  举报

导航