这题是有这个数就取出位置,没有就看插入到哪去,简单点想就是插进去,排个序,看看位置。代码如下:
class Solution(object):
def searchInsert(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
nums.append(target)
nums.sort()
return nums.index(target)
后面看应该直接有个函数的,可以直接调用来看插哪