Import 2022-12-01 19:15

Longest Sequence that Makes the Greatest Sum

Algorithm

Longest Sequence that Makes the Greatest Sum

Question 输入一个整形数组,数组里有正数也有负数。 数组中连续的一个或多个整数组成一个子数组,每个子数组都有一个和。 求所有子数组的和的最大值。要求时间复杂度为O(n)。 例如输入的数组为1, -2, 3, 10, -4, 7, 2, -5,和最大的子数组为3, 10, -4, 7, 2, 因此输出为该子数组的和18。 From a set of positive and negative integers, find the longest sequence that makes the greatest sum. It is required to have the time complexity of O(n)

By Nicholas Wong