Skip to content
This repository was archived by the owner on Jun 2, 2024. It is now read-only.

Commit 18e53ca

Browse files
authored
added java folder (#875)
1 parent e69f7bd commit 18e53ca

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class binarySearchR {
2+
public static void main(String[] args) {
3+
int[] arr= {2, 4, 5, 6,8, 9, 10,23,26, 29};
4+
int target= 4;
5+
System.out.println(search(arr, target, 0, arr.length-1));
6+
}
7+
static int search(int[] arr, int target, int start, int end){
8+
if (start>end){
9+
return -1;
10+
}
11+
12+
int mid= start+(end-start)/2;
13+
14+
if (arr[mid]==target){
15+
return mid;
16+
}
17+
if (target <arr[mid]){
18+
search(arr, target, start, mid-1);
19+
}
20+
return search(arr,target, mid+1, end);
21+
}
22+
}

0 commit comments

Comments
 (0)