Description

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

You may assume no duplicates in the array.

Example 1:

Input: [,,,],
Output:

Example 2:

Input: [,,,],
Output:

Example 3:

Input: [,,,],
Output:

Example 4:

Input: [,,,],
Output:

解题思路:在当前索引的值小于目标值时,索引递增。在while循环中判断索引的值,防止数组索引越界

C#代码:

public class Solution {
public int SearchInsert(int[] nums, int target) {
if(nums.Length == )
return ;
int index = ;
while(nums[index] < target){
index++;
if(index == nums.Length)
break;
}
return index;
}
}

开始渐渐习惯了LeetCode的题目描述和解题规范。继续加油

最新文章

  1. html drag api 在firefox 下 拖动出现新窗口的解决办法
  2. 如何让win10实现关机确认-暂没确认
  3. html5 datalist自动完成
  4. C# 连接mongodb副本集+分片读写分离及学习资料
  5. nodejs框架express实现登录
  6. 在Windows中使用MinGW编译X264
  7. Codeforces Round #Pi (Div. 2) C. Geometric Progression map
  8. 扩展jQuery easyui datagrid增加动态改变列编辑的类型
  9. 【转】Struts2中的MethodFilterInterceptor(转)
  10. C# 配置文件读取与修改
  11. python_基本语法_01
  12. js call方法
  13. APK改之理 手游修改改编安卓程序工具安装使用教程
  14. [Swift]LeetCode207. 课程表 | Course Schedule
  15. Guava Cache探索及spring项目整合GuavaCache实例
  16. Appium学习笔记2_Android获取元素篇
  17. Hadoop介绍-2.分布式计算框架Hadoop原理及架构全解
  18. .Net AppDomain详解(一)
  19. 每日英语:The Toy Mogul Who Became A Billionaire Through His Fight To The Death With Barbie
  20. PAT 1040 Longest Symmetric String[dp][难]

热门文章

  1. win10下RabbitMQ的安装和配置
  2. linux 系统管理--进程管理
  3. Elasticsearch index
  4. java.sql.SQLException: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation &#39;=&#39;
  5. 揭秘阿里云WAF背后神秘的AI智能防御体系
  6. bzoj 2013
  7. hdu 5885 XM Reserves (FFT建模)
  8. OC学习篇之---总结和学习目录
  9. python 网络编程:socket(二)
  10. ssm项目配置多个数据源