Skip to content

Instantly share code, notes, and snippets.

@kamath
Last active October 1, 2020 00:21
Show Gist options
  • Save kamath/f24f8605e8b940854aeeee286ebbe8c5 to your computer and use it in GitHub Desktop.
Save kamath/f24f8605e8b940854aeeee286ebbe8c5 to your computer and use it in GitHub Desktop.
class Solution:
def firstMissingPositive(self, nums: List[int]) -> int:
if nums == []:
return 1
maxval = max(nums)
if maxval <= 0:
return 1
nums = set(nums)
for i in range(1, maxval):
if i not in nums:
return i
return maxval + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment