Skip to content

Instantly share code, notes, and snippets.

@mindthink mindthink/41.py
Created Mar 10, 2017

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
You can’t perform that action at this time.