Skip to content

Instantly share code, notes, and snippets.

@mindthink
Created March 10, 2017 00:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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