8000 add 2224 · githubniraj/Leetcode@c7cc1e7 · GitHub
[go: up one dir, main page]

Skip to content

Commit c7cc1e7

Browse files
add 2224
1 parent 0138a7b commit c7cc1e7

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ _If you like this project, please leave me a star._ ★
8383
| 2236 |[Root Equals Sum of Children](https://leetcode.com/problems/root-equals-sum-of-children/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2236.java) || Easy ||
8484
| 2235 |[Add Two Integers](https://leetcode.com/problems/add-two-integers/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2235.java) | [:tv:](https://youtu.be/Qubhoqoks6I) | Easy ||
8585
| 2229 |[Check if an Array Is Consecutive](https://leetcode.com/problems/check-if-an-array-is-consecutive/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2229.java) || Easy ||
86+
| 2224 |[Minimum Number of Operations to Convert Time](https://leetcode.com/problems/minimum-number-of-operations-to-convert-time/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2224.java) || Easy ||
8687
| 2220 |[Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2220.java) || Easy ||
8788
| 2215 |[Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2215.java) || Easy ||
8889
| 2210 |[Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2210.java) || Easy ||
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _2224 {
4+
public static class Solution1 {
5+
public int convertTime(String current, String correct) {
6+
if (current.equals(correct)) {
7+
return 0;
8+
}
9+
int ops = 0;
10+
String[] startHourAndMinute = current.split(":");
11+
int start = 60 * Integer.parseInt(startHourAndMinute[0]) + Integer.parseInt(startHourAndMinute[1]);
12+
String[] endHourAndMinute = correct.split(":");
13+
int end = 60 * Integer.parseInt(endHourAndMinute[0]) + Integer.parseInt(endHourAndMinute[1]);
14+
int[] addons = new int[]{1, 5, 15, 60};
15+
int index = 3;
16+
while (start < end) {
17+
if (start + addons[index] == end) {
18+
return ops + 1;
19+
} else if (start + addons[index] < end) {
20+
start += addons[index];
21+
ops++;
22+
} else {
23+
index--;
24+
}
25+
}
26+
return ops;
27+
}
28+
}
29+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._2224;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _2224Test {
10+
private static _2224.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _2224.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(3, solution1.convertTime("02:30", "04:35"));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(1, solution1.convertTime("11:00", "11:01"));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)
0