Skip to content

Latest commit

 

History

History
32 lines (25 loc) · 592 Bytes

035._search_insert_position.md

File metadata and controls

32 lines (25 loc) · 592 Bytes

###35. Search Insert Position

题目: https://leetcode.com/problems/search-insert-position/

难度:

Medium

递归

class Solution(object):
    def searchInsert(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: int
        """
        n = len(nums)
        if target <= nums[0]:
            return 0
        if target > nums[n-1]:
            return n
        for i in range(1,n):
            if target == nums[i]:
                return i
            elif target > nums[i-1] and target < nums[i]:
                return i