Skip to content

Instantly share code, notes, and snippets.

@Desolve
Created July 1, 2019 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Desolve/97cea741906acfed250c644a263524df to your computer and use it in GitHub Desktop.
Save Desolve/97cea741906acfed250c644a263524df to your computer and use it in GitHub Desktop.
0035 Search Insert Position
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