标签:
题目描述:public class Solution {
public string GetPermutation(int n, int k)
{
var nums = new List<int>();
var total = 1;
for(var i = 1;i <= n; i++)
{
total *= i;
nums.Add(i);
}
var ret = "";
k--;
while(n > 0)
{
// total represent as (n-1)!
total /= n;
// take the nums[k / (n-1)!] element
var index = k / total;
var x = nums[index];
ret += x;
nums.RemoveAt(index);
// next k would be k%(n-1)!
k = k % total;
n--;
}
return ret;
}
}版权声明:本文为博主原创文章,未经博主允许不得转载。
LeetCode -- Permutation Sequence
标签:
原文地址:http://blog.csdn.net/lan_liang/article/details/49531109