Skip to content

Commit 971815e

Browse files
author
mykoo
committed
missing-number
1 parent abbf59a commit 971815e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

missing-number/GUMUNYEONG.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
var missingNumber = function (nums) {
6+
nums = nums.sort();
7+
8+
for (let i = 0; i < nums.length; i++) {
9+
if (nums[i] !== i) return i;
10+
}
11+
12+
return nums.length;
13+
};
14+
15+
// TC
16+
// nums 정렬을 하기 위해서 순회 (길이 n)
17+
// 빠진 숫자를 찾기위해서 순회 (최대길이 n)
18+
// O(2n) 따라서 시간 복잡도는 O(n)
19+
20+
// SC
21+
// 길이가 n인 배열을 저장할 공간 필요
22+
// O(n)

0 commit comments

Comments
 (0)