mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 03:27:07 +00:00
Time: 52 ms (74.16%), Space: 14.6 MB (98.67%) - LeetHub
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
class Solution:
|
||||||
|
def searchInsert(self, nums: List[int], target: int) -> int:
|
||||||
|
start = 0
|
||||||
|
end = len(nums) - 1
|
||||||
|
|
||||||
|
while end - start > 0:
|
||||||
|
midpoint = int((end - start) / 2) + start
|
||||||
|
|
||||||
|
if nums[midpoint] == target:
|
||||||
|
return midpoint
|
||||||
|
elif nums[midpoint] > target:
|
||||||
|
end = midpoint - 1
|
||||||
|
else:
|
||||||
|
start = midpoint + 1
|
||||||
|
|
||||||
|
if nums[start] >= target:
|
||||||
|
return start
|
||||||
|
else:
|
||||||
|
return end + 1
|
||||||
Reference in New Issue
Block a user