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: [1,3,5,6], 5
Output: 2

Example 2:

Input: [1,3,5,6], 2
Output: 1

Example 3:

Input: [1,3,5,6], 7
Output: 4

Example 4:

Input: [1,3,5,6], 0
Output: 0
 class Solution {
public:
int searchInsert(vector<int>& nums, int target) {
int s = nums.size();
for(int i = ; i < s; i++) {
if(target <= nums[i]) {
return i;
}
}
return s;
}
};

最新文章

  1. 2016 年 11 月 12 个轻量级的 JavaScript 库
  2. (转)java缓存技术,记录
  3. ANDROID学习书单
  4. Android中的Intent详解
  5. Maven-本地安装
  6. 终于把HDU的第一页做完了
  7. Java如何将控制台上的结果保存到文件
  8. python偏函数(functool.partail)
  9. linux 打补丁 2原理
  10. php验证码封装
  11. delphi的TFileStream 内存流
  12. Linux crontab任务调度
  13. 图书管理系统 (c语言实现) (全部代码)
  14. 2017-11-4—模拟PID电路(参考ADN8834datasheet)
  15. 关于js-angularJS的路由传参
  16. 【查阅】教你使用SQL SERVER复制
  17. 查看windows上次开机时间
  18. vue2.0 keep-alive最佳实践
  19. sqlserver清除缓存(转载)
  20. 【架构师之路】 LVS+Keepalived实现高可用负载均衡

热门文章

  1. 通过sql语句查询出来的结果字段没有到对应实体类时的处理方法
  2. C#位数不足补零
  3. 如何使用 SSL 证书配置端口
  4. jsp页面的传值(popup)
  5. c# TCP高性能通信
  6. jquery mobile 移动web(1)
  7. Js操作DOM及获取浏览器高度以及宽度
  8. Python常用的数据类型
  9. Django中ORM常用字段类型及参数
  10. (第02节)集成Sping框架