Skip to content

Commit cc47d80

Browse files
committed
Missing Number
1 parent 51e59ce commit cc47d80

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

missing-number/TonyKim9401.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// TC: O(n log n)
2+
// SC: O(n)
3+
class Solution {
4+
public int missingNumber(int[] nums) {
5+
Arrays.sort(nums);
6+
int idx = 1;
7+
int n = nums.length;
8+
for (; idx < n; idx++) {
9+
if (nums[idx] - 1 != nums[idx-1]) return nums[idx] - 1;
10+
}
11+
return nums[idx-1] == n ? 0 : n;
12+
}
13+
}

0 commit comments

Comments
 (0)