Python Accepted 42 ms


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

Log in to reply
 

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