35. Search Insert Position
1. 我的AC
方法一
class Solution(object):
def searchInsert(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
if target in nums:
return nums.index(target)
else:
for i in range(len(nums)):
if target < nums[i]:
return i
return i + 1
方法二
class Solution(object):
def searchInsert(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
return len([num for num in nums if num < target])
本文标题:35. Search Insert Position
本文链接:https://www.haomeiwen.com/subject/tlgmuqtx.html
网友评论