1、求整數數組中連續幾個數相加最大和:數組
// 例:var arr = [1,5,29,-30,22,9,-68]
參考代碼:
function aabd(array) {
if (array.length < 0) return 0;
var sum = array[0],
tempsum = array[0];
for (var i = 1; i < array.length; i++) {
tempsum = (tempsum < 0) ? array[i] : tempsum + array[i];
sum = (tempsum > sum) ? tempsum : sum;
}
return sum;
}
複製代碼