Skip to content

Commit e726f6d

Browse files
authored
Create smallest-missing-integer-greater-than-sequential-prefix-sum.py
1 parent 044e566 commit e726f6d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
# hash table
5+
class Solution(object):
6+
def missingInteger(self, nums):
7+
"""
8+
:type nums: List[int]
9+
:rtype: int
10+
"""
11+
total = nums[0]
12+
for i in xrange(1, len(nums)):
13+
if nums[i] != nums[i-1]+1:
14+
break
15+
total += nums[i]
16+
lookup = set(nums)
17+
while total in lookup:
18+
total += 1
19+
return total

0 commit comments

Comments
 (0)