您好,登錄后才能下訂單哦!
科大訊飛的一個線下筆試題
對遞歸也一直不熟悉
題目:求一個數(shù)列的最大值,用遞歸形式;
public class blanket{ public static void main(String[] args) { int[] a = {1,9,2,5,3,7,4,6,12,435,67,23,232,564564,5}; int max1 = max(a,0,0); System.out.println(max1); // return max1; } public static int max(int[] a,int index,int max){ if(index == a.length) return max; max = Math.max(max, a[index]); index++; return max(a,index,max); } }
簡直是瞎寫的,沒想到竟然可以。美滋滋。求大佬指教可以修改的地方。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。