leetCode 35.搜索插入位置 c++
2019-04-08 11:03
323 查看
[code]#include <iostream> #include <vector> using namespace std; class Solution { public: int searchInsert(vector<int>& nums, int target) { int low = 0; int hight = nums.size() - 1; int mid = 0; while (low <= hight){ mid = (low + hight) / 2; if (nums[mid] < target){ low = mid + 1; } else if (nums[mid] > target){ hight = mid - 1; } else{ return mid; } } return nums[mid] > target ? mid : mid + 1; } }; int main(){ vector<int> a = { 1, 3, 5, 6 }; Solution s; int b = s.searchInsert(a, 2); cout << b; return 0; }
相关文章推荐
- LeetCode35. 搜索插入位置(java)
- LeetCode35. 搜索插入位置
- leetcode 35. Search Insert Position搜索插入位置(二分查找)
- LeetCode 题 - 35. 搜索插入位置
- LeetCode 35. 搜索插入位置
- Leetcode35. 搜索插入位置(python3)
- 【LeetCode】35. 搜索插入位置
- Leetcode 35. 搜索插入位置
- LeetCode 35. 搜索插入位置 Python
- leetcode35.搜索插入位置
- Leetcode 35_搜索插入位置 --python
- leetcode-搜索插入位置-二分查找
- Leetcode题库-搜索插入位置(java语言版)
- leetcode首题! 35. Search Insert Position 搜索插入位置
- leetCode 35.Search Insert Position (搜索插入位置) 解题思路和方法
- LeetCode:第35题:搜索插入位置(search-insert-position)
- (LeetCode每日一刷11)搜索插入位置
- 【LeetCode】[35] 搜索插入位置
- [LeetCode] Search Insert Position 搜索插入位置
- LeetCode第35题:搜索插入位置