【LeetCode OJ】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
代码:
class Solution
{
public:
int searchInsert(int A[], int n, int target)
{
if (target < A[])
return ;
if (target>A[n-])
return n;
for (int i = ; i < n; ++i)
{
if (A[i] == target)
return i;
else if (A[i]<target&&A[i+]>target)
return i+;
}
return ;
}
};
【LeetCode OJ】Search Insert Position的更多相关文章
- LeetCode OJ 35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the ...
- LeetCode OJ:Search Insert Position(查找插入位置)
Given a sorted array and a target value, return the index if the target is found. If not, return the ...
- [Leetcode][Python]35: Search Insert Position
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 35: Search Insert Positionhttps://oj.le ...
- Leetcode 二分查找 Search Insert Position
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie Search Insert Position Total Accepted: 14279 T ...
- 【LeetCode OJ】Interleaving String
Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...
- 【LeetCode OJ】Reverse Words in a String
Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...
- 【Leetcode】【Medium】Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the ...
- 【题解】【数组】【查找】【Leetcode】Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the ...
- 【算法】LeetCode算法题-Search Insert Position
这是悦乐书的第152次更新,第154篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第11题(顺位题号是35).给定排序数组和目标值,如果找到目标,则返回索引. 如果没有, ...
随机推荐
- SAP OBYC自动记账的实例说明 +VALUE STRING
对Value String定义:定义了一系列的步骤优先顺序,每一个步骤都连接到不同的过账事务码,而这个顺序本身就称作价值串.价值串你可以看作是一种记账的规则,为物料移动或者发票校验包含了一系列的科目分 ...
- win10: This file can't be opened
win10打开bat脚本,不能运行,提示This file can't be opened. 解决方法如下: http://johnklann.com/these-files-cant-be-open ...
- SpringMVC系列(十四)Spring MVC的运行流程
Spring MVC的运行流程图: 1.首先看能不能发送请求到Spring MVC的DispatcherServlet的url-pattern2.如果能发送请求,就看在Spring MVC中是否存在对 ...
- ZooKeeper系列之二:Zookeeper常用命令
https://my.oschina.net/u/347386/blog/313037
- svn管理码云项目
1.设置SVN管理项目 进入项目->管理 2.获取SVN地址 3.SVN添加项目.单击右键 -> 检出->版本库Url(这里填写svn地址)
- 【python-proxy by sockets5】pysocks
pip install pysocks https://stackoverflow.com/questions/2317849/how-can-i-use-a-socks-4-5-proxy-with ...
- .net的session详解 存储模式 存到数据库中 使用范围与大小限制 生命周期
Session又称为会话状态,是Web系统中最常用的状态,用于维护和当前浏览器实例相关的一些信息.举个例子来说,我们可以把已登录用户的用户名放在Session中,这样就能通过判断Session中的某个 ...
- ubuntu 的chmod 和 chown
1.chown改文件或目录的所有者和群组权限 格式 chown [OPTION]... [OWNER][:[GROUP]] FILE... 参数: -R 递归操作当前目录下的所有目录和文件: -h 更 ...
- Salience Model
Who is a stakeholder? Simply anyone with a stake in the project either direct or indirect. PMBOK say ...
- 教你ABBYY FineReader 12添加图像的技巧
ABBYY FineReader 12是一款OCR图片文字识别软件,而且强大的它现在还可使用快速扫描窗口中的快速打开.扫描并保存为图像或任务自动化任务,在没有进行预处理和OCR的ABBYY FineR ...