题目链接

【题解】

还是那句话,想知道l或者r所在的数字的含义
就想想它最后一次执行的时候在干什么就行。

【代码】

class Solution {
public:
int searchInsert(vector<int>& nums, int target) {
int len = nums.size();
int l = 0,r = len-1;
while (l<=r){
int mid = (l+r)/2;
if (nums[mid]>target){
r = mid-1;
}else{
//nums[mid]<=target
l = mid+1;
}
}
if (l-1>=0 && nums[l-1]==target){
return l-1;
}else return l;
}
};

最新文章

  1. C#需知--长度可变参数--Params
  2. js函数的传参是按值传对递
  3. Tridiv:基于 Web 的 CSS 编辑器,创建炫丽 3D 图形
  4. JProfiler使用入门(一)——准备工作
  5. 【转】12 款优秀的 JavaScript MVC 框架评估
  6. [算法] get_lucky_price price
  7. iOS &#183; 安装RVM cocoaPods 及问题解决
  8. Gartner Publishes 2014 Magic Quadrant for SIEM and Critical Capabilities for SIEM Reports
  9. OC基础10:基本的C语言特性1
  10. 链表的实现 -- 数据结构与算法的javascript描述 第六章
  11. Redis 3.0集群搭建/配置/FAQ
  12. JAVA Timer定时器使用方法(一)
  13. 安卓组件-BroadcastReceiver
  14. Failed to register Grid Infrastructure type ora.mdns.type
  15. #007 C语言大作业学生管理系统第四天
  16. Python静态方法(staticmethod)和类方法(classmthod)
  17. oday获取系统最高权限的代码
  18. C# 语言历史版本和特性
  19. linux 空间释放,mysql数据库空间释放
  20. SharpZipLib 压缩ZIP导出

热门文章

  1. PHP 利用 curl 发送 post get del put patch 请求
  2. [POJ3735]Training little cats
  3. [CSP-S模拟测试]:旅行(数学+线段树)
  4. Gym-100676E Time Limit Exceeded?
  5. linux知识总结与问题总结
  6. English-Difference between original and source
  7. flysql 里两种传参的方式
  8. idhttp提交post
  9. Linux 通配符和特殊符号
  10. code for QTP and ALM