MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / Solution

Class Solution

Python/35.SearchInsertPosition.py:6–18  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#Memory: 5.97%
5
6class Solution:
7 def searchInsert(self, nums: List[int], target: int) -> int:
8 l = 0
9 r = len(nums)-1
10 while l <= r:
11 m = (l+r)//2
12 if m == r and target > nums[m]:
13 return m + 1
14 if target > nums[m]:
15 l = m + 1
16 else:
17 r = m - 1
18 return m

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected