Skip to content

Commit f63ad48

Browse files
committed
add missing number solution
1 parent 66b88c9 commit f63ad48

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

missing-number/Tessa1217.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 0 ~ n까지 고유한 숫자들로 이루어진 배열 nums가 주어질 때 해당 범위 내에서 없어진 숫자를 찾으세요.
3+
*/
4+
class Solution {
5+
6+
// 시간복잡도: O(n), 공간복잡도: O(n)
7+
public int missingNumber(int[] nums) {
8+
9+
boolean[] visitNum = new boolean[nums.length + 1];
10+
11+
for (int i = 0; i < nums.length; i++) {
12+
visitNum[nums[i]] = true;
13+
}
14+
15+
for (int i = 0; i < visitNum.length; i++) {
16+
if (!visitNum[i]) {
17+
return i;
18+
}
19+
}
20+
21+
return 0;
22+
}
23+
}
24+

0 commit comments

Comments
 (0)