Skip to content

Commit e99f831

Browse files
add 1904
1 parent 060d9f1 commit e99f831

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1904|[The Number of Full Rounds You Have Played](https://leetcode.com/problems/the-number-of-full-rounds-you-have-played/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1904.java) ||Medium|String, Greedy|
1112
|1903|[Largest Odd Number in String](https://leetcode.com/problems/largest-odd-number-in-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1903.java) ||Easy|Greedy|
1213
|1897|[Redistribute Characters to Make All Strings Equal](https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1897.java) ||Easy|String, Greedy|
1314
|1886|[Determine Whether Matrix Can Be Obtained By Rotation](https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1886.java) ||Easy|Array|
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1904 {
4+
public static class Solution1 {
5+
public int numberOfRounds(String startTime, String finishTime) {
6+
int rounds = 0;
7+
int startHour = Integer.parseInt(startTime.split(":")[0]);
8+
int endHour = Integer.parseInt(finishTime.split(":")[0]);
9+
int startMin = Integer.parseInt(startTime.split(":")[1]);
10+
int endMin = Integer.parseInt(finishTime.split(":")[1]);
11+
if (endHour < startHour) {
12+
endHour += 24;
13+
} else if (endHour == startHour && endMin < startMin) {
14+
endHour += 24;
15+
}
16+
if (startHour == endHour) {
17+
if (startMin == 0 && endMin >= 15) {
18+
rounds++;
19+
}
20+
if (startMin <= 15 && endMin >= 30) {
21+
rounds++;
22+
}
23+
if (startMin <= 30 && endMin >= 45) {
24+
rounds++;
25+
}
26+
return rounds;
27+
} else {
28+
//compute all full rounds in the start hour
29+
if (startMin == 0) {
30+
rounds += 4;
31+
} else if (startMin <= 15) {
32+
rounds += 3;
33+
} else if (startMin <= 30) {
34+
rounds += 2;
35+
} else if (startMin <= 45) {
36+
rounds++;
37+
}
38+
39+
//compute all full rounds in the finish hour
40+
if (endMin >= 45) {
41+
rounds += 3;
42+
} else if (endMin >= 30) {
43+
rounds += 2;
44+
} else if (endMin >= 15) {
45+
rounds++;
46+
}
47+
48+
//compute all full rounds in the all full hours between finishHour and startHour
49+
rounds += (endHour - startHour - 1) * 4;
50+
return rounds;
51+
}
52+
}
53+
}
54+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1904;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1904Test {
10+
private static _1904.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1904.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(1, solution1.numberOfRounds("12:01", "12:44"));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(95, solution1.numberOfRounds("00:01", "00:00"));
25+
}
26+
27+
@Test
28+
public void test3() {
29+
assertEquals(40, solution1.numberOfRounds("20:00", "06:00"));
30+
}
31+
32+
@Test
33+
public void test4() {
34+
assertEquals(55, solution1.numberOfRounds("04:54", "18:51"));
35+
}
36+
37+
@Test
38+
public void test5() {
39+
assertEquals(0, solution1.numberOfRounds("23:46", "00:01"));
40+
}
41+
42+
@Test
43+
public void test6() {
44+
assertEquals(39, solution1.numberOfRounds("18:51", "04:54"));
45+
}
46+
47+
@Test
48+
public void test9() {
49+
assertEquals(39, solution1.numberOfRounds("18:51", "04:50"));
50+
}
51+
52+
@Test
53+
public void test7() {
54+
assertEquals(2, solution1.numberOfRounds("00:01", "00:57"));
55+
}
56+
57+
@Test
58+
public void test8() {
59+
assertEquals(6, solution1.numberOfRounds("00:01", "01:57"));
60+
}
61+
62+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy