二分查找
public int binarySearch(int[] array, int target) {
int left = 0, right = array.length - 1, mid;
while (left target) {
right = mid - 1;
} else {
left = mid + 1;
}
}
return -1;
}
实际的题目
参考链接
- 二分查找代码模板
- Fast InvSqrt() 扩展阅读
- https://leetcode-cn.com/problems/sqrtx/
- https://leetcode-cn.com/problems/valid-perfect-square/
- https://leetcode-cn.com/problems/search-in-rotated-sorted-array/
- https://leetcode-cn.com/problems/search-a-2d-matrix/
- https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/