일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 시바견
- Convert Sorted List to Binary Search Tree
- attribute
- kaggle
- LeetCode
- Python Implementation
- Generator
- data science
- 109. Convert Sorted List to Binary Search Tree
- 운영체제
- 30. Substring with Concatenation of All Words
- concurrency
- 315. Count of Smaller Numbers After Self
- Decorator
- iterator
- Python
- Class
- DWG
- shiba
- Substring with Concatenation of All Words
- 밴픽
- Python Code
- 컴퓨터의 구조
- Protocol
- 43. Multiply Strings
- 프로그래머스
- Regular Expression
- 파이썬
- t1
- 715. Range Module
Archives
- Today
- Total
Scribbling
LeetCode: 89. Gray Code 본문
n = 0 n = 1 n=2 n = 3
000 001 101 1100
100 1101
1001
1000
e.g. n=3 -> 100 + 1000, 101 + 1000, 001 + 1000, 000 + 1000
-> 역순 + 2의 n-1승
class Solution:
def grayCode(self, n: int) -> List[int]:
ret = [0]
for i in range(n):
ret += [x + pow(2, i) for x in reversed(ret)]
return ret
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 98. Validate Binary Search Tree (0) | 2021.10.09 |
---|---|
LeetCode: 99. Recover Binary Search Tree (0) | 2021.10.08 |
LeetCode: 126. Word Ladder II (0) | 2021.10.06 |
LeetCode: 86. Partition List (0) | 2021.10.06 |
LeetCode: 82. Remove Duplicates from Sorted List II (0) | 2021.10.06 |