class Solution {
public int search(int[] arr, int target) {
int i = 0;
int j = arr.length;
int mid;
while (i + 1 < j) {
mid = (i + j) >>> 1;
if (target < arr[mid]) {
j = mid;
} else {
i = mid;
}
}
return arr[i] == target ? i : -1;
}
}
LeetCode-704:二分查找(Java语言实现)
最新推荐文章于 2024-08-17 22:06:38 发布