Skip to content

Commit 2367085

Browse files
committed
solve missing number
1 parent 0ebd4a5 commit 2367085

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

missing-number/sora0319.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public int missingNumber(int[] nums) {
3+
int result = 0;
4+
int[] counts = new int[nums.length+1];
5+
6+
for(int n : nums){
7+
counts[n] = 1;
8+
}
9+
10+
for(int i = 0; i < counts.length; i++){
11+
if(counts[i] == 0){
12+
result = i;
13+
break;
14+
}
15+
}
16+
17+
return result;
18+
}
19+
}
20+

0 commit comments

Comments
 (0)