算法Sedgewick第四版-第1章基础-1.4 Analysis of Algorithms-007按位置,找出数组相关最大值 Given an arraya[]of N real numbers, design a linear-time algorithm to find the maximum value ofa[j] - a[i]wherej≥i. 1packagealgorithms.analysis14;23publicclassBest {45publicstaticvoidmain(String[] args...
1packagealgorithms.analysis14;23publicclassBest {45publicstaticvoidmain(String[] args) {6double[] a = {5.0, 4.0, 3.0 ,6.0,1.0};7intN =a.length;8doublebest = 0.0;9doublemin = a[0];10for(inti = 0; i < N; i++) {11min =Math.min(a[i], min);12best = Math.max(a[i] -mi...