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.

Here are few examples.
[1,3,5,6], 5 → 2
[1,3,5,6], 2 → 1
[1,3,5,6], 7 → 4
[1,3,5,6], 0 → 0

很简单,没的说。

class Solution {
public:
int searchInsert(vector<int>& nums, int target) {
int ans=lower_bound(nums.begin(),nums.end(),target)-nums.begin();
return ans;
}
};

最新文章

  1. CentOS 7 防火墙 firewall 的使用
  2. Quartz2D简介
  3. BZOJ-1975 魔法猪学院 K短路 (A*+SPFA)
  4. JQuery中对Select的option项的添加、删除、取值
  5. 开源 java CMS - FreeCMS2.3 留言管理
  6. URAL 1553. Caves and Tunnels 树链拆分
  7. chapter8_3 c代码和错误
  8. nginx之 nginx + tomcat + redis 负载均衡且session一致性
  9. Hibernate学习笔记二
  10. SpringCloud的Hystrix(二) 某消费者应用(如:ui、网关)访问的多个微服务的断路监控
  11. 转--&gt;&gt;mysql的bin log
  12. hbase-0.92.1表备份还原
  13. 关于python的多行注释,启动新浏览器,循环语句乘法口诀
  14. jTimer
  15. java UCnter 单点登录 对接。
  16. DevExpress ASP.NET Bootstrap Controls v18.2新功能详解(一)
  17. 关于tomcat和sessionCookieName和SESSION_PARAMETER_NAME以及disableURLRewriting参数原理和使用
  18. spring @Bean注解解释
  19. Mongodb网络好文章
  20. jsoncpp 构造空数组

热门文章

  1. python 3 关于requests库的 text / content /json
  2. 闪屏Flash动画
  3. apple-touch-icon-precomposed 和 apple-touch-icon属性区别
  4. springmvc demo
  5. POJ 286 Y2K Accounting Bug【简单暴力】
  6. java高级主题
  7. JavaScript-Confirm用法
  8. 我的Android进阶之旅------>Android无第三方Jar包的源代报错:The current class path entry belongs to container ...的解决方法
  9. JVM相关的几个基本概念
  10. lua的弱弱引用表