class Solution {
public:
int searchInsert(vector<int>& nums, int target) {
int n=nums.size();
for(int i=0;i<=n-1;i++){
if(nums[i]>=target) return i;
}
return n;
}
};
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
n = len(nums);
for i in range(len(nums)):
if nums[i]>=target:
return i;
return n;
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
if target in nums:
return nums.index(target)
else:
nums.append(target)
nums.sort()
return nums.index(target)
35. 搜索插入位置-力扣
最新推荐文章于 2024-08-25 06:11:42 发布