[刷题]Search Insert Position
2015-04-07 22:01
218 查看
[LintCode]Search Insert Position
public class Solution { /** * param A : an integer sorted array * param target : an integer to be inserted * return : an integer */ public int searchInsert(int[] A, int target) { // 2015-4-7 binary search if (A == null || A.length == 0) { return 0; } int start = 0; int end = A.length - 1; while (start + 1 < end) { int mid = (start + end) / 2; if (A[mid] >= target) { end = mid; } else { start = mid; } } if (A[start] >= target) { return start; } else if (A[end] >= target) { return end; } else { return end + 1; } } }
相关文章推荐
- leetcode-35- Search Insert Position
- [leetcode]35. Search Insert Position
- 【leetcode】【35】Search Insert Position
- [LeetCode35]Search Insert Position
- Search Insert Position
- Search Insert Position Leetcode 非二分查找法
- leetcode 35. Search Insert Position
- 35. Search Insert Position
- [LeetCode]Search Insert Position
- [Leetcode]Search Insert Position
- leetcode——Search Insert Position 二分查找 binary search
- LeetCode OJ Search Insert Position
- Search Insert Position
- LeetCode - 35. Search Insert Position
- [leetcode题后感]search insert position
- leetcode35: Search Insert Position
- Leetcode: Search Insert Position
- 35. Search Insert Position
- leetcode---search-insert-position---查找
- Search Insert Position