Python Easy Solution 44ms


  • -1
    S
    def searchInsert(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: int
            """
            if target not in nums:
                nums.append(target)
                nums.sort()
            return nums.index(target)

  • 1
    W

    The time complexity of the algorithm -> the time complexity of “nums.sort()" ->o(nlogn)

    it may slower than other search algorithm when quantity of data is large

    but this algorithm is really clear


Log in to reply
 

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