Skip to content

Latest commit

 

History

History
24 lines (23 loc) · 554 Bytes

35. Search Insert Position-python.md

File metadata and controls

24 lines (23 loc) · 554 Bytes
class Solution:
    def searchInsert(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: int
        """
        start = 0
        end = len(nums)-1
        if target>nums[end]:
            return end+1
        while start<end:
            mid= (start+end)//2
            if nums[mid]<target:
                start = mid+1
            elif nums[mid]>target:
                end =mid
            else:
                start = mid
                break
                    
        return start