溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

遞歸求數(shù)組的最大值

發(fā)布時間:2020-06-04 08:09:42 來源:網(wǎng)絡(luò) 閱讀:1347 作者:努力的C 欄目:建站服務(wù)器

科大訊飛的一個線下筆試題

對遞歸也一直不熟悉

題目:求一個數(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);
	}
}

簡直是瞎寫的,沒想到竟然可以。美滋滋。求大佬指教可以修改的地方。

向AI問一下細(xì)節(jié)

免責(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)容。

AI