[LeetCode 60] Permutation Sequence
The set [1, 2, 3, … , n]
contains a total of n! unique permutations.
By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3):
* 1. "123"
* 2. "132"
* 3. "213"
* 4. "231"
* 5. "312"
* 6. "321"
Given n and k, return the kth permutation sequence.
Note: Given n will be between 1 and 9 inclusive.
DiffcultyMedium
Similar Problems
[LeetCode ] Next Permutation Medium
[LeetCode ] Permutations Medium
Analysis
这题很明显需要用到 backtrack 思路、
主要有两种方式
1、处理某个元素后,把其从原数组中删除 2、处理某个元素时,通过 swap 把它放在每次要递归的那部分数组的首位
方法一
方法二