[LeetCode][Python3] 89. Gray Code
2019. 9. 3. 00:08 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/gray-code/
My Solution :
class Solution:
def grayCode(self, n):
def dfs():
if len(path) == 2**n:
return path[:]
num = path[-1]
visited[num] = 1
for i in range(n):
cand = num ^ 1 << i
if not visited[cand]:
path.append(cand)
ret = dfs()
if ret:
return ret
path.pop()
visited[num] = 0
path = [0]
visited = [0]*(2**n)
return dfs()
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 90. Subsets II (0) | 2019.09.17 |
---|---|
[LeetCode][Python3] 739. Daily Temperatures (0) | 2019.09.12 |
[LeetCode][Python3] 401. Binary Watch (0) | 2019.09.05 |
[LeetCode][Python3] 692. Top K Frequent Words (0) | 2019.09.03 |
[LeetCode][Python3] 357. Count Numbers with Unique Digits (0) | 2019.08.29 |
[LeetCode][Python3] 996. Number of Squareful Arrays (0) | 2019.08.28 |
[LeetCode][Python3] 174. Dungeon Game (0) | 2019.08.28 |
[LeetCode][Python3] 77. Combinations (0) | 2019.08.25 |
최근에 달린 댓글 최근에 달린 댓글