Skip to content

Commit 210f887

Browse files
authored
Create minimum-number-of-operations-to-convert-time.py
1 parent 1e3216d commit 210f887

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(1)
2+
# Space: O(1)
3+
4+
# greedy
5+
class Solution(object):
6+
def convertTime(self, current, correct):
7+
"""
8+
:type current: str
9+
:type correct: str
10+
:rtype: int
11+
"""
12+
OPS = (60, 15, 5, 1)
13+
diff = (int(correct[:2])*60+int(correct[3:]))-(int(current[:2])*60+int(current[3:]))
14+
result = 0
15+
for x in OPS:
16+
q, diff = divmod(diff, x)
17+
result += q
18+
return result

0 commit comments

Comments
 (0)