60. Permutation Sequence
2019-05-10
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 for _n_ = 3:
"123"
"132"
"213"
"231"
"312"
"321"
Given _n_ and _k_, return the _k_th permutation sequence.
Note:
- Given _n_ will be between 1 and 9 inclusive.
- Given _k_ will be between 1 and _n_! inclusive.
Example 1:
1 | Input: n = 3, k = 3 |
Example 2:
1 | Input: n = 4, k = 9 |
Code:
1 | class Solution(object): |