题解 | #二叉树中和为某一值的路径(一)#javascript:void(0);
连续子数组的最大和
http://www.nowcoder.com/practice/459bd355da1549fa8a49e350bf3df484
public class Solution {
public int FindGreatestSumOfSubArray(int[] array) {
int sum = 0;
// int max = 0; 报错,全为负数时候返回的是初始值0
int max = array[0];
for (int i = 0; i < array.length; i++) {
sum = Math.max(sum + array[i], array[i]); 要的是最大值,通过和来与最大值进行比较
max = Math.max(max, sum);
}
return max;
}
}
阿里云成长空间 763人发布
