Created
April 26, 2013 05:00
-
-
Save st0le/5465118 to your computer and use it in GitHub Desktop.
Find Gap in Sorted Array - Binary Search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_first_gap(lst, low , high): | |
if high - low == lst[high] - lst[low]: return -1 | |
if low + 1 == high: return lst[low] + 1 | |
mid = (low + high) / 2 | |
if mid - low < lst[mid] - lst[low]: #gap in first half | |
return find_first_gap(lst,low,mid) | |
else: | |
return find_first_gap(lst,mid,high) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment