Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Given an unsorted array of positive integers, return the smallest positive integer not in the array.
- #[5,3,2,2,1] => 4
- #[1,4,3] => 2
- #[6, 5, 4] => 1
- def foo(myArray):
- myArray.sort()
- count = 1
- for i in range(len(myArray)):
- if myArray[i] == count:
- if (i < len(myArray)-1) and (myArray[i+1] == myArray[i])
- continue # the next value is the same as this one
- else
- count += 1
- continue
- else:
- return count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement