Created
March 10, 2017 00:30
-
-
Save mindthink/ac97f5a123c22dd4089ab764a671f33f to your computer and use it in GitHub Desktop.
leetcode 41:First Missing Positive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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