LeetCode OJ Search Insert Position
来源:互联网 发布:单片机公司有哪些 编辑:程序博客网 时间:2024/06/05 07:53
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) { int low = 0, high = n - 1, mid; while (low <= high) { mid = low + (high - low) / 2; if (A[mid] == target) return mid; else if (A[mid] < target) low = mid + 1; else high = mid - 1; } return high + 1; }};
0 0
- LeetCode OJ:Search Insert Position
- LeetCode OJ - Search Insert Position
- [LeetCode OJ]Search Insert Position
- LeetCode OJ Search Insert Position
- LeetCode OJ - Search Insert Position
- 【LeetCode OJ 035】Search Insert Position
- <LeetCode OJ> 35. Search Insert Position
- LeetCode OJ-35-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
- OS X Yosemite 10.10 安装brew
- OpenGL入门12——雾
- 29、简单的apk安装器
- (素材源码)猫猫学IOS(六)UI之iOS热门游戏_超级猜图
- #个人赛第五场解题总结#
- LeetCode OJ Search Insert Position
- LeetCode Remove Duplicates from Sorted Array
- 【java编程】java反射之基础
- FOJ有奖月赛-2015年03月
- 【DP|状态压缩+预处理】POJ-1185 炮兵阵地
- LeetCode OJ Swap Nodes in Pairs
- Java内部类详解
- 欢迎使用CSDN-markdown编辑器
- LeetCode OJ Multiply Strings