Leetcode 792 Solution
This article provides solution to leetcode question 792 (binary-search)
Access this page by simply typing in "lcs 792" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/binary-search
Solution
class Solution:
def search(self, nums: List[int], target: int) -> int:
l = 0
r = len(nums) - 1
while l < r:
m = (l + r) // 2
if nums[m] > target:
r = m
elif nums[m] < target:
l = m + 1
else:
return m
return l if nums[l] == target else -1