50,499
社区成员
发帖
与我相关
我的任务
分享
public class Test {
private int max;
public static void main(String[] args) {
Test test = new Test();
int i = test.test(new int[]{-456,1,3,5,7,9,3});
System.out.println(i);
}
public int test(int[] arr){
test(arr, Integer.MIN_VALUE, 0);
return max;
}
private void test(int[] arr,int nextMax,int nextIndex){
max = arr[nextIndex] > nextMax ? arr[nextIndex]:nextMax;
nextIndex++;
if(nextIndex < arr.length){
test(arr, max, nextIndex);
}
}
}
public class Test {
private int max;
public static void main(String[] args) {
Test test = new Test();
test.test(new int[]{-456,1,3,5,7,9,3}, Integer.MIN_VALUE,0);
System.out.println(test.max);
}
public void test(int[] arr,int nextMax,int nextIndex){
max = arr[nextIndex] > nextMax ? arr[nextIndex]:nextMax;
nextIndex++;
if(nextIndex < arr.length){
test(arr, max, nextIndex);
}
}
}
static int max(int[] array) {
return max(array, 0);
}
static int max(int[] array, int from) {
if (from == array.length - 1) {
return array[from];
}
return Math.max(array[from], max(array, from + 1));
}