Skip to content

Commit

Permalink
missing number solution
Browse files Browse the repository at this point in the history
  • Loading branch information
yoon-turtle committed Jan 2, 2025
1 parent d9fcd03 commit e2b6507
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions missing-number/yoonthecoder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var missingNumber = function (nums) {
// store all the elemenst from nums in a Set
const set = new Set(nums);

// check the missing number by iterating through the index
for (i = 0; i <= nums.length; i++) {
if (!set.has(i)) {
return i;
}
}
};

// Time complexity: O(n);
// Space complexity: O(n);

0 comments on commit e2b6507

Please sign in to comment.