leetcode---search-insert-position---查找
来源:互联网 发布:网络配线架报价 编辑:程序博客网 时间:2024/05/16 04:25
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 h = n-1; int l = 0; while(l <= h) { int m = (l + h) / 2; if(A[m] == target) return m; else if(A[m] < target) l = m + 1; else h = m - 1; } return l; }};
阅读全文
0 0
- leetcode---search-insert-position---查找
- LeetCode Search Insert Position查找插入位置
- Leetcode 二分查找 Search Insert Position
- LeetCode @ Search Insert Position 二分查找
- [leetcode] 【查找】 35. Search Insert Position
- [leetcode-查找]--35. Search Insert Position
- LeetCode 35. Search Insert Position 二分查找
- (二分查找)LeetCode#35. Search Insert Position
- leetcode——Search Insert Position 二分查找 binary search
- 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
- 自定义Unity调色板
- uva 11536 尺取法 滑动窗口
- Java管理扩展指南之MBean简介
- loadrunner Lr_类函数之lr_db_executeSQLStatement()
- Django--Model与ORM
- leetcode---search-insert-position---查找
- 【NOIP2013】华容道
- 学习Docker(2017-10-1)
- 用Scrapy爬动画列表
- oracle学习
- loadrunner Lr_类函数之lr_db_getValue()
- bootstrap 格栅
- Python:Django项目( 一)!
- 浅析一句话木马