6-line Python solution, similar to 34.Search for a Range, 44ms


  • 0
    K
    def searchInsert(self, nums, target):
        left, right = 0, len(nums) - 1
        while left <= right:
            mid = (left + right) / 2
            if target > nums[mid]: left = mid + 1
            else: right = mid - 1
        return left

Log in to reply
 

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