repl.it
@Wilmor21/

Recursion Testing

Java

No description

fork
loading
Files
  • Main.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Main {
	public static void Main(String[] args) {
		int[] arr = {11,13,25,26,29,30,31,32};
		mystery(arr,0,arr.length - 1, 14);
	}
	public static int mystery(int[], arr, int low, int high, int target) {
		System.out.println("called");
		int mid = (low + high) / 2;
		if (low > high) {
			return low;
		}
		if (target > arr[mid]) {
			return mystery(arr, mid + 1, high, target);
		}
		if (target < arr[mid]) {
			return mystery(arr, low, mid - 1, target);
		}
		return mid;
	}
}