Skip to content

Commit

Permalink
Create: 35-Search-Insert-Position.py
Browse files Browse the repository at this point in the history
  • Loading branch information
UdayGarg committed Oct 7, 2022
1 parent c50d6fa commit 5451da9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions python/35-Search-Insert-Position.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
# O(log n) and O(1)


low, high = 0, len(nums)
while low<high:
mid = low +(high - low) // 2
if target > nums[mid]:
low = mid + 1
else:
high = mid
return low

0 comments on commit 5451da9

Please sign in to comment.