[LeetCode][Python3] 401. Binary Watch
2019. 9. 5. 00:02 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/binary-watch/
My Solution :
class Solution:
def readBinaryWatch(self, num):
if num == 0:
return ["0:00"]
def convert_to_time(path):
hour = minute = 0
for i in path:
if i < 4:
hour += 2**(3-i)
else:
minute += 2**(9-i)
if hour < 12 and minute < 60:
return '%d:%02d' % (hour, minute)
def dfs(path, i, remain):
if remain == 1:
t = convert_to_time(path+[i])
if t:
ans.append(t)
elif remain <= 10-i:
path.append(i)
for j in range(i+1, 10):
dfs(path, j, remain-1)
path.pop()
ans = []
for i in range(10):
dfs([], i, num)
return ans
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 338. Counting Bits (0) | 2019.09.24 |
---|---|
[LeetCode][Python3] 406. Queue Reconstruction by Height (0) | 2019.09.23 |
[LeetCode][Python3] 90. Subsets II (0) | 2019.09.17 |
[LeetCode][Python3] 739. Daily Temperatures (0) | 2019.09.12 |
[LeetCode][Python3] 692. Top K Frequent Words (0) | 2019.09.03 |
[LeetCode][Python3] 89. Gray Code (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 |
최근에 달린 댓글 최근에 달린 댓글