Skip to content

Commit

Permalink
missing number solution
Browse files Browse the repository at this point in the history
  • Loading branch information
limlimjo committed Jan 2, 2025
1 parent e57df08 commit 5c235d2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions missing-number/limlimjo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @param {number[]} nums
* @return {number}
*/
var missingNumber = function (nums) {
// 1. nums 정렬
nums.sort((a, b) => a - b);
// 2. for문 돌며 빠진 숫자 찾기
for (let i = 0; i <= nums.length; i++) {
if (nums[i] !== i) {
return i;
}
}
};

// 시간 복잡도: O(nlogn)
// 공간 복잡도: O(1)

0 comments on commit 5c235d2

Please sign in to comment.