Advertisement
mos_basik

Backplane Phone Screen 2

Oct 28th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. #Given an unsorted array of positive integers, return the smallest positive integer not in the array.
  2.  
  3. #[5,3,2,2,1] => 4
  4. #[1,4,3] => 2
  5. #[6, 5, 4] => 1
  6.  
  7. def foo(myArray):
  8.     myArray.sort()
  9.     count = 1
  10.     for i in range(len(myArray)):
  11.         if myArray[i] == count:
  12.             if (i < len(myArray)-1) and (myArray[i+1] == myArray[i])
  13.                 continue # the next value is the same as this one
  14.             else
  15.                 count += 1
  16.                 continue
  17.         else:
  18.             return count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement