일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- Convert Sorted List to Binary Search Tree
- data science
- Substring with Concatenation of All Words
- Class
- 43. Multiply Strings
- 315. Count of Smaller Numbers After Self
- 컴퓨터의 구조
- Protocol
- Python
- 715. Range Module
- 밴픽
- kaggle
- 운영체제
- Decorator
- Python Code
- 시바견
- LeetCode
- Generator
- iterator
- Regular Expression
- attribute
- concurrency
- 파이썬
- 프로그래머스
- shiba
- 30. Substring with Concatenation of All Words
- Python Implementation
- t1
- DWG
- 109. Convert Sorted List to Binary Search Tree
Archives
- Today
- Total
Scribbling
LeetCode: 60. Permutation Sequence 본문
class Solution:
def getPermutation(self, n: int, k: int) -> str:
def factorial(n):
if n == 1:
return 1
return n * factorial(n-1)
nums = [str(i) for i in range(1, n+1)]
if k == 1:
return ''.join(nums)
k -= 1
ret = ''
while k > 0:
x = factorial(n-1)
if k >= x:
quotient = k // x
k -= quotient * x
ret += nums.pop(quotient)
else:
ret += nums.pop(0)
n -= 1
ret += ''.join(nums)
return ret
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 62. Unique Paths (0) | 2021.09.24 |
---|---|
LeetCode: 61. Rotate List (0) | 2021.09.24 |
LeetCode: 59. Spiral Matrix II (0) | 2021.09.24 |
LeetCode: 53. Maximum Subarray (0) | 2021.09.24 |
LeetCode: 57. Insert Interval (0) | 2021.09.24 |