【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).给定排序数组和目标值,如果找到目标,则返回索引. 如果没有, ...
随机推荐
- c算法
斐波那契 void main() { ]={, }, i; ;i<=;i++) //这里需要注意,for循环虽然<=9, 还有个i++ { a[i] = a[i-] + a[i-]; pr ...
- 用ARM实现音乐电子相册
(前段时间在做嵌入式的课程设计,特将学习心得整理如下) 一.开发工具及环境介绍 1.ARM处理器 ARM处理器是一个32位元精简指令集(RISC)处理器架构,其广泛地使用在许多嵌入式系统设计. ARM ...
- e788. 取消JSpinner的键盘编辑能力
// Create a nummber spinner JSpinner spinner = new JSpinner(); // Disable keyboard edits in the spin ...
- Dynamics CRM 2015/2016 Web API:聚合查询
各位小伙伴们,今天是博主2016年发的第一篇文章.首先祝大家新年快乐.工资Double,哈哈.今天我们来看一个比較重要的Feature--使用Web API运行FetchXML查询! 对的,各位.你们 ...
- mysql错误代码对照表较完整 mysql_errno()
From: http://blog.csdn.net/aidenliu/article/details/5925604 mysql错误代码对照表较完整 0101 属于其他进程的专用标志. 0102 ...
- Scripting.FileSystemObject对象的详细技巧指南
Scripting.FileSystemObject对象的详细技巧指南 FileSystemObject对象提供对计算机文件系统的访问: powered by 25175.net 在代码内操作文本文件 ...
- GCT之数学公式(平面解析几何)
- PyQt环境配置
1.下载python 登录Python官网,目前最新的版本是3.6.3,网址为:https://www.python.org/downloads/release/python-363/ 选中Windo ...
- mysql5.7 启动报发生系统错误2
1. http://dev.mysql.com/downloads/mysql/ 下载mysql5.7 zip包 2. 下载好后解压文件,解压的内容如图,您可以把内容解压到想要的位置 ...
- nginx配置http协议和tcp协议配置文件案例
注意 nginx 1.9版本之后才支持 tcp #user nobody;worker_processes 1; #error_log logs/error.log;#error_log logs/e ...