Skip to content

Commit c0d9a25

Browse files
authored
Create the-number-of-full-rounds-you-have-played.py
1 parent ddf3d86 commit c0d9a25

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Time: O(1)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def numberOfRounds(self, startTime, finishTime):
6+
"""
7+
:type startTime: str
8+
:type finishTime: str
9+
:rtype: int
10+
"""
11+
h1, m1 = map(int, startTime.split(":"))
12+
h2, m2 = map(int, finishTime.split(":"))
13+
start = h1*60+m1
14+
finish = h2*60+m2
15+
if start > finish:
16+
finish += 1440
17+
return max(finish//15-(start+15-1)//15, 0)
18+
19+
20+
# Time: O(1)
21+
# Space: O(1)
22+
class Solution2(object):
23+
def numberOfRounds(self, startTime, finishTime):
24+
"""
25+
:type startTime: str
26+
:type finishTime: str
27+
:rtype: int
28+
"""
29+
h1, m1 = map(int, startTime.split(":"))
30+
h2, m2 = map(int, finishTime.split(":"))
31+
if m1 > m2:
32+
h2 -= 1
33+
m2 += 60
34+
return max((h2-h1)%24*4 + m2//15 - (m1+15-1)//15, 0)

0 commit comments

Comments
 (0)