mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-10 04:26:27 +08:00
prevent (ub+lb) overflow
This commit is contained in:
@ -23,7 +23,7 @@ class BinarySearch
|
|||||||
if ( lb > ub)
|
if ( lb > ub)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int mid = (ub+lb)/2;
|
int mid = (ub+lb) >>> 1;
|
||||||
int comp = key.compareTo(array[mid]);
|
int comp = key.compareTo(array[mid]);
|
||||||
|
|
||||||
if (comp < 0)
|
if (comp < 0)
|
||||||
|
Reference in New Issue
Block a user