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 kth permutation sequence.
Note:
- Given n will be between 1 and 9 inclusive.
- Given k will be between 1 and n! inclusive.
一個集合[1,2,3,…,n],它總共擁有n!種不同的排列組合。
以下照順序列出了n=3的時候的所有組合:
- "123"
- "132"
- "213"
- "231"
- "312"
- "321"
給予n和k,請回傳第k種排列。
提示:
- n將會介於1到9之間(包含)。
- k將會介於1到n!之間(包含)。
algorithm
函式庫裡面的next_permutation
。LeetCode
C++