leetcode-10-basic
35. Search Insert Position
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
解题思路:
挺简单的。。
int searchInsert(vector<int>& nums, int target) {
int i;
if (target > nums[nums.size()-1])
return nums.size();
if (target < nums[0])
return 0;
for (i = 0; i < nums.size(); i++) {
if (target <= nums[i])
return i;
}
}
leetcode-10-basic的更多相关文章
- [LeetCode] 224. Basic Calculator 基本计算器
Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...
- [LeetCode] 227. Basic Calculator II 基本计算器 II
Implement a basic calculator to evaluate a simple expression string. The expression string contains ...
- Leetcode 10. 正则表达式匹配 - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...
- leetcode 10 Regular Expression Matching(简单正则表达式匹配)
最近代码写的少了,而leetcode一直想做一个python,c/c++解题报告的专题,c/c++一直是我非常喜欢的,c语言编程练习的重要性体现在linux内核编程以及一些大公司算法上机的要求,pyt ...
- [LeetCode] 772. Basic Calculator III 基本计算器之三
Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...
- Java for LeetCode 227 Basic Calculator II
Implement a basic calculator to evaluate a simple expression string. The expression string contains ...
- Java for LeetCode 224 Basic Calculator
Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...
- (medium)LeetCode 224.Basic Calculator
Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...
- (medium)LeetCode 227.Basic Calculator II
Implement a basic calculator to evaluate a simple expression string. The expression string contains ...
- [LeetCode] 227. Basic Calculator II 基本计算器之二
Implement a basic calculator to evaluate a simple expression string. The expression string contains ...
随机推荐
- CentOS,net core2 sdk nginx、supervisor、mysql
CentOS下 .net core2 sdk nginx.supervisor.mysql环境搭建 作为.neter,看到.net core 2.0的正式发布,心里是有点小激动的,迫不及待的体验了一把 ...
- 从I/O事件到阻塞、非阻塞、poll到epoll的理解过程
I/O事件 I/O事件 非阻塞I/O.在了解非阻塞I/O之前,需要先了解I/O事件 我们知道,内核有缓冲区.假设有两个进程A,B,进程B想读进程A写入的东西(即进程A做写操作,B做读操作).进程A ...
- SmartWeatherAPI C#版
private string GetKey(string areaId, string type, string date, string appId, string privateKey) { va ...
- SQL server 游标,随机数使用
SELECT * FROM [goods] DECLARE test_cursor CURSOR scroll FOR SELECT goods_no, [unitprice] FROM [goods ...
- 微信android手机中点击大图片会自动放大图片
自己使用的是微信Android客户端,使用img标签的src属性将图片设置好了以后,在微信中调试,点击图片竟然放大,自己没写放大图片的方法,也没有调用wx.previewImage()方法,最后查找, ...
- Mvc异常处理器
using System; using System.Text; using EMS.Domains.Core; using System.Web.Mvc; using Json.Net; using ...
- 第十九章 排查和调试Web程序 之 防止和排查运行时问题
1. 概述 常见的几种运行时问题包括 错误数据.慢于预期的响应.未知行为 或者 未处理的异常. Visual Studio 提供了 排查.跟踪 和 日志 等工具 来帮助排查系统的问题.有些情况还需要插 ...
- windows下利用intellij idea等工具开发erlang
今天突然想在家里去年新买的电脑上写点erlang代码,然后可耻的发现家里的电脑上竟然没有开发环境,果然是去年6月以后没写过erlang代码么╮(╯▽╰)╭? 首先下载需要用的几样东西: ...
- Country roads take me home, to the place I belong.
Country roads take me home, to the place I belong.故乡的路,带我回家吧,回到我期盼已久的归宿.
- They say Rome wasn't built in a day, and yet what a difference a day makes.
They say Rome wasn't built in a day, and yet what a difference a day makes.有人说罗马不是一天建成的,但一天却能改变很多事.