| 6 | * */ |
| 7 | |
| 8 | public class GetMax { |
| 9 | public static void main(String[] args) { |
| 10 | int[] arr = {1,6,9,8,4,7,3,1,2,19}; |
| 11 | System.out.println(getMax(arr)); |
| 12 | } |
| 13 | |
| 14 | private static int getMax(int[] arr) { |
| 15 | if(arr.length == 0) { |
| 16 | throw new RuntimeException("Your array is empty!"); |
| 17 | } |
| 18 | return process(arr, 0, arr.length - 1); |
| 19 | } |
| 20 | |
| 21 | private static int process(int[] arr, int left, int right) { |
| 22 | if(left == right) { |
| 23 | return arr[left]; |
| 24 | } |
| 25 | int mid = left + ((right - left) >> 1); |
| 26 | int leftMax = process(arr, left, mid); |
| 27 | int rightMax = process(arr, mid + 1, right); |
| 28 | return Math.max(leftMax,rightMax); |
| 29 | } |
| 30 | } |
nothing calls this directly
no outgoing calls
no test coverage detected