【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).给定排序数组和目标值,如果找到目标,则返回索引. 如果没有, ...
随机推荐
- 【Python】windows电脑 python3.6安装lxml库
1.下载lxml的wheel文件 https://download.lfd.uci.edu/pythonlibs/t5yhk4lc/lxml-4.2.1-cp36-cp36m-win32.whl 其他 ...
- HttpComponents-Client学习
HttpComponents-Client 学习 官方文档:http://hc.apache.org/httpcomponents-client-ga/tutorial/html/index.html ...
- C# wkhtmltopdf 将html转pdf
一.转换程序代码如下: public string HtmlToPdf(string url) { bool success = true; // string dwbh = url.Split('? ...
- mysql的字符串函数
From: http://www.cnblogs.com/xiaochaohuashengmi/archive/2010/12/13/1904330.html 对于针对字符串位置的操作,第一个位置被标 ...
- 前端图片压缩(纯js)
html代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <t ...
- 几个免费IP地址查询API接口
转:http://blog.csdn.net/ishxiao/article/details/52670242 -------------------------------------------- ...
- iOS : Blur Effect
http://blog.bubbly.net/2013/09/11/slick-tricks-for-ios-blur-effect/ Full sample sources available at ...
- [Learn AF3]第二章 App Framework 3.0的组件View——AF3的驱动引擎
View:af3中的驱动引擎 组件名称:View 使用说明:按照官方的说法,view组件是af3的“驱动引擎(driving force)”,view是af3应用的基础,一个app中可以包 ...
- 软件设计模式之单例模式(JAVA)
什么是单例模式? 单例模式是一种常用的软件设计模式.在它的核心结构中只包含一个被称为单例类的特殊类.通过单例模式可以保证系统中一个类只有一个实例而且该实例易于外界访问,从而方便对实例个数的控制并节约系 ...
- php解析出带层级关系的mpp文件
本来要使用DHX gantt插件自带的API做导入,可是做完后,又发现不稳定,不能访问了 可能是屏蔽掉了 所以又想起可以使用javaBridge,借用java的MPXJ php解析mpp的 上一篇介绍 ...