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