Skip to content

Commit 187e677

Browse files
add 2446
1 parent 25760b4 commit 187e677

File tree

3 files changed

+60
-0
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src

3 files changed

+60
-0
lines changed

Diff for: paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
| 2485 | [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2485.java) || Easy ||
5050
| 2467 | [Convert the Temperature](https://leetcode.com/problems/convert-the-temperature/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2469.java) || Easy ||
5151
| 2455 | [Average Value of Even Numbers That Are Divisible by Three](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2455.java) || Easy ||
52+
| 2446 | [Determine if Two Events Have Conflict](https://leetcode.com/problems/determine-if-two-events-have-conflict/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2446.java) || Easy |
5253
| 2441 | [Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2441.java) || Easy ||
5354
| 2437 | [Number of Valid Clock Times](https://leetcode.com/problems/number-of-valid-clock-times/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2437.java) | | Easy ||
5455
| 2433 | [Find The Original Array of Prefix Xor](https://leetcode.com/problems/find-the-original-array-of-prefix-xor/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2433.java) | [:tv:](https://youtu.be/idcT-p_DDrI) | Medium ||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
public class _2446 {
4+
public static class Solution1 {
5+
public boolean haveConflict(String[] event1, String[] event2) {
6+
int startMinute1 = getAbsoluteMinute(event1[0]);
7+
int endMinute1 = getAbsoluteMinute(event1[1]);
8+
int startMinute2 = getAbsoluteMinute(event2[0]);
9+
int endMinute2 = getAbsoluteMinute(event2[1]);
10+
for (int h = 0; h <= 23; h++) {
11+
for (int m = 0; m <= 59; m++) {
12+
int currentTime = h * 60 + m;
13+
if (inTime(currentTime, startMinute1, endMinute1) && inTime(currentTime, startMinute2, endMinute2)) {
14+
return true;
15+
}
16+
}
17+
}
18+
return false;
19+
}
20+
21+
private boolean inTime(int currentMinute, int startMinute, int endMinute) {
22+
if (currentMinute >= startMinute && currentMinute <= endMinute) {
23+
return true;
24+
}
25+
return false;
26+
}
27+
28+
private int getAbsoluteMinute(String eventStart) {
29+
String[] startParts = eventStart.split(":");
30+
String startHour = startParts[0];
31+
String startMinute = startParts[1];
32+
int startHourInt = Integer.parseInt(startHour);
33+
int startMinuteInt = Integer.parseInt(startMinute);
34+
return startHourInt * 60 + startMinuteInt;
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder.thirdthousand;
2+
3+
import com.fishercoder.solutions.thirdthousand._2446;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertTrue;
8+
9+
public class _2446Test {
10+
private static _2446.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _2446.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertTrue(solution1.haveConflict(new String[]{"01:15", "02:00"}, new String[]{"02:00", "03:00"}));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)