function maxSonArray(array) {
let sum = -Infinity, all = -Infinity, start, end;
for (let i = 0; i < array.length; i++) {
if (sum + array[i] > array[i]) {
sum += array[i];
} else {
sum = array[i];
array[i] > all ? start = i : undefined;
}
if (sum > all) {
all = sum;
end = i;
}
}
return { start: start, end: end, all: all };
}
写得不好的地方希望大佬指正
网友评论