当前位置: 首页> 游戏> 游戏 > 简单题35-搜索插入位置(Java and Python)20240919

简单题35-搜索插入位置(Java and Python)20240919

时间:2025/7/11 15:36:36来源:https://blog.csdn.net/Sep21m_wyy/article/details/142355037 浏览次数:0次
问题描述:

在这里插入图片描述

Java:
class Solution {public int searchInsert(int[] nums, int target) {int k = 0;int i =0;while(i<nums.length){if(nums[i]==target){return i;}if(nums[i]<=target){k = i+1;}i++;}return k;}}
class Solution(object):def searchInsert(self, nums, target):""":type nums: List[int]:type target: int:rtype: int"""i = index = 0while(i<len(nums)):if(nums[i] == target):return iif(nums[i]<=target):index = i+1i +=1return index
关键字:简单题35-搜索插入位置(Java and Python)20240919

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: