Skip to content

Commit 81a563b

Browse files
authored
Create The Number of Full Rounds You Have Played.java
1 parent a499e5d commit 81a563b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public int numberOfRounds(String startTime, String finishTime) {
3+
int startMinutes = toMinutes(startTime);
4+
int finishMinutes = toMinutes(finishTime);
5+
int roundedStart = toNextQuarter(startMinutes);
6+
int roundedFinish = toPreviousQuarter(finishMinutes);
7+
if (startMinutes < finishMinutes) {
8+
return Math.max(0, (roundedFinish - roundedStart) / 15);
9+
}
10+
return (24 * 60 - roundedStart + roundedFinish) / 15;
11+
}
12+
13+
public static int toMinutes(String s) {
14+
return Integer.parseInt(s.substring(0, 2)) * 60 + Integer.parseInt(s.substring(3, 5));
15+
}
16+
17+
public static int toNextQuarter(int time) {
18+
return ((time + 14) / 15) * 15;
19+
}
20+
21+
public static int toPreviousQuarter(int time) {
22+
return (time / 15) * 15;
23+
}
24+
}

0 commit comments

Comments
 (0)