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

Commitb3eb2c4

Browse files
add 1893
1 parent7937b87 commitb3eb2c4

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
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|
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.Arrays;
4+
5+
publicclass_1893 {
6+
publicstaticclassSolution1 {
7+
publicbooleanisCovered(int[][]ranges,intleft,intright) {
8+
Arrays.sort(ranges, (a,b) ->a[0] !=b[0] ?a[0] -b[0] :a[1] -b[1]);
9+
intchecked =left;
10+
for (int[]range :ranges) {
11+
while (checked >=range[0] &&checked <=range[1]) {
12+
checked++;
13+
}
14+
}
15+
returnchecked >= (right +1);
16+
}
17+
}
18+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1893;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1893Test {
10+
privatestatic_1893.Solution1solution1;
11+
privatestaticint[][]ranges;
12+
13+
@BeforeClass
14+
publicstaticvoidsetup() {
15+
solution1 =new_1893.Solution1();
16+
}
17+
18+
@Test
19+
publicvoidtest1() {
20+
ranges =newint[][]{
21+
{1,10},
22+
{10,20}
23+
};
24+
assertEquals(false,solution1.isCovered(ranges,21,21));
25+
}
26+
27+
@Test
28+
publicvoidtest2() {
29+
ranges =newint[][]{
30+
{50,50}
31+
};
32+
assertEquals(false,solution1.isCovered(ranges,1,50));
33+
}
34+
35+
@Test
36+
publicvoidtest3() {
37+
ranges =newint[][]{
38+
{1,10},
39+
{10,20}
40+
};
41+
assertEquals(false,solution1.isCovered(ranges,21,25));
42+
}
43+
44+
@Test
45+
publicvoidtest4() {
46+
ranges =newint[][]{
47+
{1,50}
48+
};
49+
assertEquals(true,solution1.isCovered(ranges,1,50));
50+
}
51+
52+
@Test
53+
publicvoidtest5() {
54+
ranges =newint[][]{
55+
{1,2}, {3,4}, {5,6}
56+
};
57+
assertEquals(true,solution1.isCovered(ranges,2,5));
58+
}
59+
60+
@Test
61+
publicvoidtest6() {
62+
ranges =newint[][]{
63+
{50,50}
64+
};
65+
assertEquals(false,solution1.isCovered(ranges,49,49));
66+
}
67+
68+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp