Skip to content

Commit 0629e9f

Browse files
add 2996
1 parent 1c3246b commit 0629e9f

File tree

3 files changed

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

3 files changed

+65
-0
lines changed

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

+1
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 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
public class _2996 {
7+
public static class Solution1 {
8+
public int missingInteger(int[] nums) {
9+
int sum = nums[0];
10+
for (int i = 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 = new HashSet<>();
18+
for (int i = 0; i < nums.length; i++) {
19+
seen.add(nums[i]);
20+
}
21+
while (seen.contains(sum)) {
22+
sum++;
23+
}
24+
return sum;
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.fishercoder.thirdthousand;
2+
3+
import com.fishercoder.solutions.thirdthousand._2996;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class _2996Test {
10+
private static _2996.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _2996.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(6, solution1.missingInteger(new int[]{1, 2, 3, 2, 5}));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(15, solution1.missingInteger(new int[]{3, 4, 5, 1, 12, 14, 13}));
25+
}
26+
27+
@Test
28+
public void test3() {
29+
assertEquals(38, solution1.missingInteger(new int[]{37, 1, 2, 9, 5, 8, 5, 2, 9, 4}));
30+
}
31+
32+
@Test
33+
public void test4() {
34+
assertEquals(95, solution1.missingInteger(new int[]{47, 48, 2, 6, 9, 5, 10, 5, 6, 7, 6, 9, 8}));
35+
}
36+
37+
}

0 commit comments

Comments
 (0)