【LeetCode】Search Insert Position
来源:互联网 发布:php求和字符串函数 编辑:程序博客网 时间:2024/05/20 05:56
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; if(target > A[n-1]) return n; for(int i = 0; i < n; i++) { if(A[i] == target) return i; if(target > A[i] && target < A[i+1]) return i+1; } }};
0 0
- LeetCode: Search Insert Position
- LeetCode Search Insert Position
- [Leetcode] Search Insert Position
- LeetCode : Search Insert Position
- [LeetCode] Search Insert Position
- [Leetcode] Search Insert Position
- [LeetCode]Search Insert Position
- [LeetCode] Search Insert Position
- LeetCode-Search Insert Position
- LeetCode - Search Insert Position
- LeetCode | Search Insert Position
- Leetcode: Search Insert Position
- 【LeetCode】Search Insert Position
- Leetcode Search Insert Position
- Leetcode: Search Insert Position
- LeetCode:Search Insert Position
- leetcode Search Insert Position
- LeetCode Search Insert Position
- 拉勾网一些事
- HDU1673 Optimal Parking
- [cocos2dx 3.0 (四)] CocoStudio生成Json文件 + 使用rapidjson获取Json数据
- 黑马程序员日记二线程 synchronized
- 任务切换
- 【LeetCode】Search Insert Position
- C++和C#中的class和struct区别
- [C++] [算法] [Linux] radix tree
- 在Linux下不重启让配置文件修改后立即生效
- 双向链表的操作
- 微信小观
- Gray码在异步FIFO中的应用
- 多进程间通信方式和多线程同步机制总结
- poj里java的一些常用的语法(转自博客http://www.blogjava.net/DreamAngel/archive/2009/10/18/298731.html)