题意:

  给一个升序的数组,如果target在里面存在了,返回其下标,若不存在,返回其插入后的下标。

思路:

  来一个简单的二分查找就行了,注意边界。

 class Solution {
public:
int searchInsert(vector<int>& nums,int target)
{
int L=, R=nums.size();
while(L<R)
{
int mid=R-(R-L+)/;
if(nums[mid]>=target) R=mid;
else L=mid+;
}
return R;
}
};

AC代码

最新文章

  1. C阶段【01】 - C基础
  2. CentOS升级Python 2.6到2.7
  3. A -- HDU 4585 Shaolin
  4. Java实现猜数游戏
  5. (剑指Offer)面试题15:链表中倒数第k个结点
  6. 一级域名301重定向到www二级域名
  7. 宏定义&amp;CodeBlocks&amp;Glib
  8. js获取上传文件的绝对路径
  9. UVA-12166 天平性质+字符处理
  10. 动态规划 POJ3616 Milking Time
  11. 01 JVM 从入门到实战 | 什么是 JVM
  12. Ambari Agent 源码分析
  13. mac 配置 ssh 到git (Could not resolve hostname github.com, Failed to connect to github.com port 443 Operation timed out)
  14. OWIN 自托管静态网站
  15. Cmder使用ls中文显示乱码解决方案
  16. [Python设计模式] 第15章 如何兼容各种DB——抽象工厂模式
  17. 向jsp中引入公共文件
  18. java 泛型的通配符和限定
  19. ueditor上传图片设置的简单实例
  20. LINQ to SQL和Entity Framework

热门文章

  1. jquery事件之事件处理函数
  2. restfull知识点
  3. nginx 服务器并发优化
  4. 解读人:朱月琴,Hippocampal proteomic alteration in triple transgenic mouse model of Alzheimer’s disease and implication of PINK 1 regulation in donepezil treatment
  5. EOS 用户权限相关命令
  6. express-http-proxy 的基础使用
  7. 外键约束 foreign key
  8. 加注解时插入权限切面@EnableDataSecurity
  9. (转)linux 中特殊符号用法详解
  10. 2 - Bootstrap-引导类-Bootstrap/ServerBootstrap