Created
May 15, 2021 17:33
-
-
Save Park-Developer/d5435f90d1e783f2c750f966a2fe4883 to your computer and use it in GitHub Desktop.
binary search using iteration
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 binary_search_iter(seq, target): | |
high , low=len(seq),0 | |
while low < high: | |
mid = (high+low)//2 | |
if target ==seq[mid]: | |
return mid | |
elif target<seq[mid]: | |
high=mid | |
else: | |
low=mid+1 | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment