Last active
October 27, 2015 20:56
-
-
Save sridatta/3e66b2a3025ef94c6e96 to your computer and use it in GitHub Desktop.
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 process_list_2(list_of_items): | |
s = set() | |
rv = [] | |
for item in list_of_items: | |
if item not in s: | |
rv.append(item) | |
return s |
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 fun(sorted_list, needle): | |
def fun_internal(low, high): | |
if not sorted_list: | |
return None | |
if low >= high: | |
return None | |
pivot_pos = (low + high) / 2 | |
if pivot_pos >= len(sorted_list): | |
return None | |
elif pivot_pos < 0: | |
return None | |
pivot = sorted_list[pivot_pos] | |
if needle == pivot: | |
return pivot | |
elif needle < pivot: | |
return fun_internal(low, pivot_pos - 1) | |
else: | |
return fun_internal(pivot_pos + 1, high) | |
return fun_internal(0, len(sorted_list) - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment