Skip to content

Commit 32c00ff

Browse files
author
Feixiang Ni
authored
Create RECURSIVE_BI.java
1 parent ca73caf commit 32c00ff

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

RECURSIVE_BI.java

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public int binarySearch(int[] a, int start, int end, int target) {
2+
if(start > end)
3+
return -1;
4+
int mid = start + (end - start) / 2;
5+
if(a[mid] == target)
6+
return mid;
7+
else if(a[mid] > target)
8+
return binarySearch(a, start, mid-1, target);
9+
else
10+
return binarySearch(a, mid+1, end, target);
11+
}

0 commit comments

Comments
 (0)