Skip to content

Commit c48048d

Browse files
donghyeon95donghyeon95
authored andcommitted
feat: Missing Number #235
1 parent dd5d98d commit c48048d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

missing-number/donghyeon95.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.util.Arrays;
2+
import java.util.Collections;
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
import java.util.stream.Collectors;
6+
7+
// O(N)
8+
class Solution {
9+
public int missingNumber(int[] nums) {
10+
Set<Integer> numSet = Arrays.stream(nums).boxed().collect(Collectors.toSet());
11+
12+
for (int i=0; i<nums.length; i++) {
13+
if (!numSet.contains(i)) return i;
14+
}
15+
16+
return nums.length;
17+
}
18+
}
19+

0 commit comments

Comments
 (0)