Skip to content

Commit b3eb2c4

Browse files
add 1893
1 parent 7937b87 commit b3eb2c4

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ _If you like this project, please leave me a star._ ★
1515
|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|
1616
|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) |[:tv:](https://youtu.be/IIt_ARZzclY)|Easy|Greedy|
1717
|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|
18+
|1893|[Check if All the Integers in a Range Are Covered](https://leetcode.com/problems/check-if-all-the-integers-in-a-range-are-covered/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1893.java) ||Easy|Array, HashTable, Prefix Sum|
1819
|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|
1920
|1880|[Check if Word Equals Summation of Two Words](https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1880.java) ||Easy|String|
2021
|1877|[Minimize Maximum Pair Sum in Array](https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1877.java) ||Medium|Greedy, Sort|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Arrays;
4+
5+
public class _1893 {
6+
public static class Solution1 {
7+
public boolean isCovered(int[][] ranges, int left, int right) {
8+
Arrays.sort(ranges, (a, b) -> a[0] != b[0] ? a[0] - b[0] : a[1] - b[1]);
9+
int checked = left;
10+
for (int[] range : ranges) {
11+
while (checked >= range[0] && checked <= range[1]) {
12+
checked++;
13+
}
14+
}
15+
return checked >= (right + 1);
16+
}
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1893;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1893Test {
10+
private static _1893.Solution1 solution1;
11+
private static int[][] ranges;
12+
13+
@BeforeClass
14+
public static void setup() {
15+
solution1 = new _1893.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
ranges = new int[][]{
21+
{1, 10},
22+
{10, 20}
23+
};
24+
assertEquals(false, solution1.isCovered(ranges, 21, 21));
25+
}
26+
27+
@Test
28+
public void test2() {
29+
ranges = new int[][]{
30+
{50, 50}
31+
};
32+
assertEquals(false, solution1.isCovered(ranges, 1, 50));
33+
}
34+
35+
@Test
36+
public void test3() {
37+
ranges = new int[][]{
38+
{1, 10},
39+
{10, 20}
40+
};
41+
assertEquals(false, solution1.isCovered(ranges, 21, 25));
42+
}
43+
44+
@Test
45+
public void test4() {
46+
ranges = new int[][]{
47+
{1, 50}
48+
};
49+
assertEquals(true, solution1.isCovered(ranges, 1, 50));
50+
}
51+
52+
@Test
53+
public void test5() {
54+
ranges = new int[][]{
55+
{1, 2}, {3, 4}, {5, 6}
56+
};
57+
assertEquals(true, solution1.isCovered(ranges, 2, 5));
58+
}
59+
60+
@Test
61+
public void test6() {
62+
ranges = new int[][]{
63+
{50, 50}
64+
};
65+
assertEquals(false, solution1.isCovered(ranges, 49, 49));
66+
}
67+
68+
}

0 commit comments

Comments
 (0)