Skip to content

Commit 10410e5

Browse files
committed
Missing Number Solution
1 parent 8f248e1 commit 10410e5

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

missing-number/doh6077.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Missing Number
2+
class Solution:
3+
def missingNumber(self, nums: List[int]) -> int:
4+
# First Solution: Time Complexity: O(n^2)
5+
n = len(nums)
6+
7+
for i in range(0,n + 1):
8+
if i not in nums:
9+
return i
10+
11+
# Time Complexity: O(n)
12+
n = len(nums)
13+
# calculate the sum of first n numbers
14+
sum_val = n * (n + 1) // 2
15+
return sum_val - sum(nums)
16+

0 commit comments

Comments
 (0)