Skip to content

Commit

Permalink
solved: leetcode: binary_search -@iamserda
Browse files Browse the repository at this point in the history
  • Loading branch information
iamserda committed Feb 25, 2025
1 parent 9800000 commit 8c49b6b
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution:
def search(self, nums: list[int], target: int) -> int:
if nums:
left = 0
right = len(nums) - 1

while left <= right:
mid = (left + right) // 2
if target > nums[mid]:
left = mid + 1
elif target < nums[mid]:
right = mid - 1
else:
return mid
return -1

0 comments on commit 8c49b6b

Please sign in to comment.