Typescript-Algorithms
    Preparing search index...

    Variable next_permutationConst

    next_permutation: (nums: number[]) => void = nextPermutation

    31.下一个排列

    整数数组的一个排列就是将其所有成员以序列或线性顺序排列。

    • 例如,arr = [1,2,3],以下这些都视为 arr 的排列:[1,2,3][1,3,2][3,1,2][2,3,1]

    下一个排列是指在字典序中大于原数组的下一个排列。如果不存在下一个更大的排列,则将数组重新排列为最小的排列(即升序排列)。

    你必须 原地 修改,只允许使用额外常数空间。


    输入: nums = [1,2,3]

    输出: [1,3,2]


    输入: nums = [3,2,1]

    输出: [1,2,3]


    输入: nums = [1,1,5]

    输出: [1,5,1]


    • 1 <= nums.length <= 100
    • 0 <= nums[i] <= 100

    Type declaration

      • (nums: number[]): void
      • Do not return anything, modify nums in-place instead.

        Parameters

        • nums: number[]

        Returns void