forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
_1904.java
54 lines (51 loc) · 1.9 KB
/
_1904.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.fishercoder.solutions;
public class _1904 {
public static class Solution1 {
public int numberOfRounds(String startTime, String finishTime) {
int rounds = 0;
int startHour = Integer.parseInt(startTime.split(":")[0]);
int endHour = Integer.parseInt(finishTime.split(":")[0]);
int startMin = Integer.parseInt(startTime.split(":")[1]);
int endMin = Integer.parseInt(finishTime.split(":")[1]);
if (endHour < startHour) {
endHour += 24;
} else if (endHour == startHour && endMin < startMin) {
endHour += 24;
}
if (startHour == endHour) {
if (startMin == 0 && endMin >= 15) {
rounds++;
}
if (startMin <= 15 && endMin >= 30) {
rounds++;
}
if (startMin <= 30 && endMin >= 45) {
rounds++;
}
return rounds;
} else {
//compute all full rounds in the start hour
if (startMin == 0) {
rounds += 4;
} else if (startMin <= 15) {
rounds += 3;
} else if (startMin <= 30) {
rounds += 2;
} else if (startMin <= 45) {
rounds++;
}
//compute all full rounds in the finish hour
if (endMin >= 45) {
rounds += 3;
} else if (endMin >= 30) {
rounds += 2;
} else if (endMin >= 15) {
rounds++;
}
//compute all full rounds in the all full hours between finishHour and startHour
rounds += (endHour - startHour - 1) * 4;
return rounds;
}
}
}
}