Skip to content

Instantly share code, notes, and snippets.

@juanitobanca
Last active March 3, 2017 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanitobanca/8cc11f19f385c4b97b49303bed4cea38 to your computer and use it in GitHub Desktop.
Save juanitobanca/8cc11f19f385c4b97b49303bed4cea38 to your computer and use it in GitHub Desktop.
def getPartitionInt( alist ):
low = 0
high = len(alist)-1
pos = len(alist)
while low <= high:
mid = (low+high)/2
if alist[mid] < 0:
low = mid + 1
elif alist[mid] >= 0 and mid < pos:
high = mid - 1
pos = mid
elif alist[mid] >= 0:
high = mid - 1
if pos == 0 or pos == len(alist):
return -1
else:
return mid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment