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

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].
原文地址:https://www.cnblogs.com/mdumpling/p/8073141.html