Created
July 1, 2019 16:16
-
-
Save Desolve/97cea741906acfed250c644a263524df to your computer and use it in GitHub Desktop.
0035 Search Insert Position
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
class Solution: | |
def searchInsert(self, nums: 'List[int]', target: 'int') -> 'int': | |
lo, up = 0, len(nums) - 1 | |
mi = (lo + up) // 2 | |
while lo <= up: | |
if nums[mi] == target: | |
return mi | |
elif nums[mi] > target: | |
up = mi - 1 | |
else: | |
lo = mi + 1 | |
mi = (lo + up) // 2 | |
return lo | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment