Created
January 12, 2019 08:57
-
-
Save jan25/a6e06a7289f7a44fa42b7536e3496726 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): | |
nums += [0] | |
for i, num in enumerate(nums): | |
while nums[i] > 0 and nums[i] < len(nums) and nums[i] != i: | |
j = nums[i] | |
prev = nums[i] | |
nums[i], nums[j] = nums[j], nums[i] | |
if nums[i] == prev: break | |
for i in range(1, len(nums)): | |
if nums[i] != i: return i | |
return len(nums) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment