Skip to content

Instantly share code, notes, and snippets.

@mindthink
Created March 10, 2017 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mindthink/ac97f5a123c22dd4089ab764a671f33f to your computer and use it in GitHub Desktop.
Save mindthink/ac97f5a123c22dd4089ab764a671f33f to your computer and use it in GitHub Desktop.
leetcode 41:First Missing Positive
class Solution(object):
def firstMissingPositive(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
max_num = len(nums) +1
nums_set = set(nums)
for i in range(1, max_num):
if i not in nums_set:
return i
return max_num
if __name__ == '__main__':
sol = Solution()
x = [10, 11, 12, 0, 0, 0]
y = [1, 2, 0]
print(sol.firstMissingPositive(y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment