Skip to content

Commit 5cccae6

Browse files
committed
feat: find the 2 missing numbers
1 parent 035652f commit 5cccae6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

medium/missing_numbers.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import java.util.*;
2+
3+
class Program {
4+
public int[] missingNumbers(int[] nums) {
5+
Set<Integer> set = new HashSet<>();
6+
for(int i = 1; i<= nums.length+2;i++) set.add(i);
7+
for(int num:nums) set.remove(num);
8+
List<Integer> list = new ArrayList<>(set);
9+
return new int[]{list.get(0),list.get(1)};
10+
}
11+
}
12+

0 commit comments

Comments
 (0)