Python clean solution


  • 0
    P
    from bisect import *
    class Solution(object):
        def binsearch(self, nums, target):
            start = 0
            end = len(nums) - 1
            
            while start <= end:
                mid = start + (end - start) // 2
                if nums[mid] == target: return True
                elif nums[mid] < target: start = mid + 1
                else: end = mid - 1
            
            return False
            
        def searchRange(self, nums, target):
            if not self.binsearch(nums, target): return [-1, -1]
            return [bisect_left(nums, target), bisect(nums, target) - 1]
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.