Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created July 5, 2013 21:25
Show Gist options
  • Save cocodrips/5937356 to your computer and use it in GitHub Desktop.
Save cocodrips/5937356 to your computer and use it in GitHub Desktop.
二分探索 再帰ver
int binarySearchRecursive(int[] array, int x, int low, int high){
if(low > high) return -1;
int mid = (low + high) / 2;
if (array[mid] < x) {
return binarySearchRecursive(array, x, mid + 1, high);
}else if(array[mid] > x){
return binarySearchRecursive(array, x, low, mid - 1);
}else{
return mid;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment