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