Skip to content

Instantly share code, notes, and snippets.

@Jason-cqtan
Created September 17, 2019 04:29
Show Gist options
  • Save Jason-cqtan/b62586f62464cef522147c5e904132b6 to your computer and use it in GitHub Desktop.
Save Jason-cqtan/b62586f62464cef522147c5e904132b6 to your computer and use it in GitHub Desktop.
php二分查找
function bin_sch($array, $low, $high, $k){
if ($low <= $high){
$mid = intval(($low+$high)/2);
if ($array[$mid] == $k){
return $mid;
}elseif ($k < $array[$mid]){
return bin_sch($array, $low, $mid-1, $k);
}else{
return bin_sch($array, $mid+1, $high, $k);
}
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment