Search Insert Position
来源:互联网 发布:淘宝手机拍摄教学 编辑:程序博客网 时间:2024/06/06 02:37
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[0]) return 0; for(int i=0;i<n;i++) { if(A[i]<target&&A[i+1]>target) return i+1; if(A[i]==target) return i; } return n; }};
0 0
- LeetCode: Search Insert Position
- Search Insert Position
- LeetCode Search Insert Position
- [Leetcode] Search Insert Position
- LeetCode : Search Insert Position
- Search Insert Position
- [LeetCode] Search Insert Position
- [Leetcode] Search Insert Position
- LeetCode34:Search Insert Position
- Search Insert Position
- [35]Search Insert Position
- Search Insert Position
- Search Insert Position
- [LeetCode]Search Insert Position
- Search Insert Position
- [LeetCode] Search Insert Position
- Search Insert Position
- Search Insert Position
- linux安装subversion1.8.9
- POJ Six Degrees of Cowvin Bacon
- Ubutun常用命令之chmod
- UVA 11044(暑假-数学(3)- B - Searching for Nessy)
- POJ 1659:Frogs' Neighborhood(Havel-Hakimi定理)
- Search Insert Position
- php 中几种while循环输出数据库中的数据代码
- MYSQL dead but pid file exists问题
- 杭电1754 I Hate It
- java自动运行任务job---quartz的运用
- Machine learning (Regression and neural networks) by Mark K Cowan
- 手机刷机弄丢文件怎么办
- linux C 中的volatile使用
- UVA 10361-Automatic Poetry