MCPcopy Create free account
hub / github.com/CCCshengjiang/algorithm / GetMax

Class GetMax

data-structure-algorithm/src/cn/cwblue/recursion/GetMax.java:8–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6* */
7
8public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected