We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8f248e1 commit 10410e5Copy full SHA for 10410e5
1 file changed
missing-number/doh6077.py
@@ -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
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