Update BinarySearch.java

master
wangsiyuan 2024-07-09 23:42:12 +08:00
parent b415741eb0
commit 922c779457
1 changed files with 2 additions and 2 deletions

View File

@ -5,10 +5,10 @@ class BinarySearch {
int i = 0 ,j = nums.length - 1;//设置指针和初始值
while (i <= j){
int m = ((i + j) / 2);
if (target < nums[m]){
if (target < nums[m]){//如果中间值大于目标值,则将右指针向左移动
j = m - 1;
}
else if (nums[m] < target){
else if (nums[m] < target){//如果中间值小于目标值,则将左指针向右移动
i = m + 1;
}
else {