Skip to content

Commit 93773ff

Browse files
committed
- Missing Number #235
1 parent a5687d5 commit 93773ff

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

missing-number/ayosecu.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from typing import List
2+
3+
class Solution:
4+
"""
5+
- Time Complexity: O(n), n = len(nums)
6+
- Space Complexity: O(1)
7+
"""
8+
def missingNumber(self, nums: List[int]) -> int:
9+
n = len(nums)
10+
total = (1 + n) * n // 2
11+
12+
for num in nums:
13+
total -= num
14+
15+
return total
16+
17+
tc = [
18+
([3, 0, 1], 2),
19+
([0, 1], 2),
20+
([9, 6, 4, 2, 3, 5, 7, 0, 1], 8)
21+
]
22+
23+
sol = Solution()
24+
for i, (n, e) in enumerate(tc, 1):
25+
r = sol.missingNumber(n)
26+
print(f"TC {i} is Passed!" if r == e else f"TC {i} is Failed! - Expected: {e}, Result: {r}")

0 commit comments

Comments
 (0)