You are given an array of integers.
You need to find the contiguous subarray of the maximum sum in . The subarray should not contain the number . Please find the maximum sum that is possible.
Note 1: The subarray can also be empty.
Note 2: The answer will fit in 32 bit-signed integer.
Input Format
The first line contains the integer . The next line contains integers representing the numbers in the array.
Constraints
Output Format
Output a single line representing the maximum sum that can be obtained.
Sample Input
5
3 4 0 1 2
Sample Output
7
Explanation
The subarray with the maximum sum that doesn’t contain a is .
Hence, the sum is.
题目大意:
求不包括元素0的最大子序列和。
题目解析:
遍历序列,当遍历到第i个元素时,判断前面的连续子序列的和是否大于0,有就加上;遍历到0元素时,自动清零。
具体代码:

给定一个包含整数的数组,找到一个没有0的连续子数组,返回其最大和。示例输入为5个整数3、4、0、1、2,输出为7,因为子数组[3, 4]的最大和为7。"
121873172,11731308,Android自定义Application与数据传递及缓存,"['移动开发', 'android', '内存管理']
&spm=1001.2101.3001.5002&articleId=88560914&d=1&t=3&u=42a96a930c0f48cfb3c31b9f9d454013)
512

被折叠的 条评论
为什么被折叠?



