Binary Search : leetcode solution in python

class Solution:
    def search(self, nums: List[int], target: int) -> int:
            low = 0
            high = len(nums)-1
            while low <= high:
                mid = low + (high - low)//2
                if nums[mid] == target:
                    return mid
                elif nums[mid] <= target:
                    low = mid + 1
                    high = mid - 1
            return -1

        except Exception as e:

Leave a Comment

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock