Simplest solution in Python


  • 0
    R
    class Solution(object):
        def searchInsert(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: int
            """
            length = len(nums)
            i = 0
            while i < length:
                if nums[i] >= target:
                    return i
                i += 1
            return length
    

Log in to reply
 

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