Leercode 35 Search Insert Position
2016-09-06 10:33
281 查看
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.
和34题差不多。
http://blog.csdn.net/accepthjp/article/details/52447635
真的不太想再二分了!
class Solution {
public:
int searchInsert(vector<int>& nums, int target) {
return lower_bound(nums.begin(),nums.end(),target)-nums.begin();;
}
};
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
和34题差不多。
http://blog.csdn.net/accepthjp/article/details/52447635
真的不太想再二分了!
class Solution {
public:
int searchInsert(vector<int>& nums, int target) {
return lower_bound(nums.begin(),nums.end(),target)-nums.begin();;
}
};
相关文章推荐
- LeetCode - 35. Search Insert Position
- LeetCode 35 Search Insert Position(查找插入位置)
- [LeetCode]35 Search Insert Position
- 35. Search Insert Position
- 【LeetCode35】【Search Insert Position】二分法查找
- LeetCode 35 — Search Insert Position(C++ Java Python)
- 35. Search Insert Position **
- Java [leetcode 35]Search Insert Position
- LeetCode-35-Search Insert Position-E
- leetcode 35 Search Insert Position
- 恍恍惚惚,哈哈,35. Search Insert Position
- 2018.04.02 leeycode 打卡 #35 . Search Insert Position
- LeetCode-35-Search Insert Position(搜素并插入指定位置)
- LeetCode 35 Search Insert Position
- 35. Search Insert Position
- [35]Search Insert Position
- 35 Search Insert Position(找到数的位置Medium)
- LeetCode 35---Search Insert Position
- LeetCode(35) Search Insert Position
- leetcode.array--35. Search Insert Position