Skip to content

Commit

Permalink
Create search-insert-position.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gabedonnan authored Feb 12, 2023
1 parent e7615b8 commit 1f9eef0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions search-insert-position.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
#indices = [n for n in range(len(nums))]
start = 0
end = len(nums) - 1
final = 0
while start <= end:
pivot = (start + end) // 2
if target > nums[pivot]:
start = pivot + 1
final = pivot + 1
elif target < nums[pivot]:
end = pivot - 1
final = pivot
else:
return pivot
return final

0 comments on commit 1f9eef0

Please sign in to comment.