일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- attribute
- Generator
- Convert Sorted List to Binary Search Tree
- iterator
- DWG
- Python Code
- 30. Substring with Concatenation of All Words
- 시바견
- Substring with Concatenation of All Words
- 315. Count of Smaller Numbers After Self
- 컴퓨터의 구조
- 109. Convert Sorted List to Binary Search Tree
- Regular Expression
- 43. Multiply Strings
- concurrency
- 프로그래머스
- 밴픽
- Decorator
- 파이썬
- kaggle
- LeetCode
- Python Implementation
- Class
- 715. Range Module
- t1
- data science
- Python
- shiba
- 운영체제
- Protocol
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 |