Skip to content

Commit d2b72e7

Browse files
Create Missing Number.py
1 parent 452ac8f commit d2b72e7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def missingNumber(self, nums: List[int]) -> int:
3+
'''
4+
num_dict = {}
5+
for num in nums:
6+
if num not in num_dict:
7+
num_dict[num] = 1
8+
9+
for num in range(len(nums)+1):
10+
if num not in num_dict:
11+
return num
12+
#hash_map approach, works fine
13+
'''
14+
#bit manipulation
15+
missing = len(nums)
16+
for i in range(len(nums)):
17+
missing ^= i^nums[i]
18+
return missing

0 commit comments

Comments
 (0)