Skip to content

Commit

Permalink
feat: Missing Number #235
Browse files Browse the repository at this point in the history
  • Loading branch information
donghyeon95 authored and donghyeon95 committed Dec 29, 2024
1 parent dd5d98d commit c48048d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions missing-number/donghyeon95.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

// O(N)
class Solution {
public int missingNumber(int[] nums) {
Set<Integer> numSet = Arrays.stream(nums).boxed().collect(Collectors.toSet());

for (int i=0; i<nums.length; i++) {
if (!numSet.contains(i)) return i;
}

return nums.length;
}
}

0 comments on commit c48048d

Please sign in to comment.