Skip to content

Instantly share code, notes, and snippets.

@jan25
Created January 12, 2019 08:57
Show Gist options
  • Save jan25/a6e06a7289f7a44fa42b7536e3496726 to your computer and use it in GitHub Desktop.
Save jan25/a6e06a7289f7a44fa42b7536e3496726 to your computer and use it in GitHub Desktop.
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