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

Commit0629e9f

Browse files
add 2996
1 parent1c3246b commit0629e9f

File tree

3 files changed

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

3 files changed

+65
-0
lines changed

‎paginated_contents/algorithms/3rd_thousand/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| # | Title | Solutions | Video | Difficulty | Tag
22
|------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|------------------------------------------|----------------------------------------------------------------------
3+
| 2996|[Smallest Missing Integer Greater Than Sequential Prefix Sum](https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2996.java)|| Easy|
34
| 2976 |[Minimum Cost to Convert String I](https://leetcode.com/problems/minimum-cost-to-convert-string-i/) |[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2976.java) | | Medium | Graph, Shortest Path
45
| 2974|[Minimum Number Game](https://leetcode.com/problems/minimum-number-game/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2974.java)|| Easy|
56
| 2970|[Count the Number of Incremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2970.java)|| Easy|
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
packagecom.fishercoder.solutions.thirdthousand;
2+
3+
importjava.util.HashSet;
4+
importjava.util.Set;
5+
6+
publicclass_2996 {
7+
publicstaticclassSolution1 {
8+
publicintmissingInteger(int[]nums) {
9+
intsum =nums[0];
10+
for (inti =1;i <nums.length;i++) {
11+
if (nums[i -1] +1 ==nums[i]) {
12+
sum +=nums[i];
13+
}else {
14+
break;
15+
}
16+
}
17+
Set<Integer>seen =newHashSet<>();
18+
for (inti =0;i <nums.length;i++) {
19+
seen.add(nums[i]);
20+
}
21+
while (seen.contains(sum)) {
22+
sum++;
23+
}
24+
returnsum;
25+
}
26+
}
27+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
packagecom.fishercoder.thirdthousand;
2+
3+
importcom.fishercoder.solutions.thirdthousand._2996;
4+
importorg.junit.jupiter.api.BeforeEach;
5+
importorg.junit.jupiter.api.Test;
6+
7+
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
8+
9+
publicclass_2996Test {
10+
privatestatic_2996.Solution1solution1;
11+
12+
@BeforeEach
13+
publicvoidsetup() {
14+
solution1 =new_2996.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(6,solution1.missingInteger(newint[]{1,2,3,2,5}));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals(15,solution1.missingInteger(newint[]{3,4,5,1,12,14,13}));
25+
}
26+
27+
@Test
28+
publicvoidtest3() {
29+
assertEquals(38,solution1.missingInteger(newint[]{37,1,2,9,5,8,5,2,9,4}));
30+
}
31+
32+
@Test
33+
publicvoidtest4() {
34+
assertEquals(95,solution1.missingInteger(newint[]{47,48,2,6,9,5,10,5,6,7,6,9,8}));
35+
}
36+
37+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp