Skip to content

Commit 7bd7d81

Browse files
authored
Create next-closest-time.py
1 parent 54ad9d7 commit 7bd7d81

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Python/next-closest-time.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Time: O(1)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def nextClosestTime(self, time):
6+
"""
7+
:type time: str
8+
:rtype: str
9+
"""
10+
h, m = time.split(":")
11+
curr = int(h) * 60 + int(m)
12+
result = None
13+
for i in xrange(curr+1, curr+1441):
14+
t = i % 1440
15+
h, m = t // 60, t % 60
16+
result = "%02d:%02d" % (h, m)
17+
if set(result) <= set(time):
18+
break
19+
return result

0 commit comments

Comments
 (0)