Last active
October 1, 2020 00:21
-
-
Save kamath/f24f8605e8b940854aeeee286ebbe8c5 to your computer and use it in GitHub Desktop.
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: | |
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