MCPcopy Create free account
hub / github.com/Hsinha11/Leetcode-solutions / search

Method search

792-binary-search/binary-search.py:2–14  ·  view source on GitHub ↗
(self, nums: List[int], target: int)

Source from the content-addressed store, hash-verified

1class Solution:
2 def search(self, nums: List[int], target: int) -> int:
3 i=0
4 j = len(nums)-1
5 while i<=j:
6 mid = (i+j)//2
7 if nums[mid]==target:
8 return mid
9 if nums[mid]> target:
10 j=mid-1
11 else:
12 i=mid+1
13
14 return -1

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected