Skip to content

Instantly share code, notes, and snippets.

@juanitobanca
Last active March 3, 2017 04:02
Embed
What would you like to do?
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