Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite99f831

Browse files
add 1904
1 parent060d9f1 commite99f831

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+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1904 {
4+
publicstaticclassSolution1 {
5+
publicintnumberOfRounds(StringstartTime,StringfinishTime) {
6+
introunds =0;
7+
intstartHour =Integer.parseInt(startTime.split(":")[0]);
8+
intendHour =Integer.parseInt(finishTime.split(":")[0]);
9+
intstartMin =Integer.parseInt(startTime.split(":")[1]);
10+
intendMin =Integer.parseInt(finishTime.split(":")[1]);
11+
if (endHour <startHour) {
12+
endHour +=24;
13+
}elseif (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+
returnrounds;
27+
}else {
28+
//compute all full rounds in the start hour
29+
if (startMin ==0) {
30+
rounds +=4;
31+
}elseif (startMin <=15) {
32+
rounds +=3;
33+
}elseif (startMin <=30) {
34+
rounds +=2;
35+
}elseif (startMin <=45) {
36+
rounds++;
37+
}
38+
39+
//compute all full rounds in the finish hour
40+
if (endMin >=45) {
41+
rounds +=3;
42+
}elseif (endMin >=30) {
43+
rounds +=2;
44+
}elseif (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+
returnrounds;
51+
}
52+
}
53+
}
54+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1904;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1904Test {
10+
privatestatic_1904.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1904.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(1,solution1.numberOfRounds("12:01","12:44"));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals(95,solution1.numberOfRounds("00:01","00:00"));
25+
}
26+
27+
@Test
28+
publicvoidtest3() {
29+
assertEquals(40,solution1.numberOfRounds("20:00","06:00"));
30+
}
31+
32+
@Test
33+
publicvoidtest4() {
34+
assertEquals(55,solution1.numberOfRounds("04:54","18:51"));
35+
}
36+
37+
@Test
38+
publicvoidtest5() {
39+
assertEquals(0,solution1.numberOfRounds("23:46","00:01"));
40+
}
41+
42+
@Test
43+
publicvoidtest6() {
44+
assertEquals(39,solution1.numberOfRounds("18:51","04:54"));
45+
}
46+
47+
@Test
48+
publicvoidtest9() {
49+
assertEquals(39,solution1.numberOfRounds("18:51","04:50"));
50+
}
51+
52+
@Test
53+
publicvoidtest7() {
54+
assertEquals(2,solution1.numberOfRounds("00:01","00:57"));
55+
}
56+
57+
@Test
58+
publicvoidtest8() {
59+
assertEquals(6,solution1.numberOfRounds("00:01","01:57"));
60+
}
61+
62+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp