Blog Archive

Friday, September 12, 2014

[leetcode]Permutation Sequence @ Python - 南郭子綦 - 博客园

[leetcode]Permutation Sequence @ Python - 南郭子綦 - 博客园: " res = ''
k -= 1
fac = 1
for i in range(1, n): fac *= i
num = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in reversed(range(n)):
curr = num[k/fac]
res += str(curr)
num.remove(curr)
if i !=0:
k %= fac
fac /= i
return res"



'via Blog this'

No comments:

Post a Comment