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):
"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.
思路:这道题我刚开始做的时候,是将这n个数全排列,然后得到第k个数列,毫无疑问,超时。后来我想到其实可以找到规律的,例如n=3,k=5,对1,2,3进行全排列,当第一个数固定时,第二个和第三个......
阅读全文