摘要: 题目描述:输入一个整形数组,数组里有正数也有负数。数组中连续的一个或多个整数组成一个子数组,每个子数组都有一个和。求所有子数组的和的最大值。要求时间复杂度为O(n)。例如输入的数组为1, -2, 3, 10, -4, 7, 2, -5,和最大的子数组为3, 10, -4, 7, 2,因此输出为该子数组的和18。View Code publicstaticvoidMaxSum(int[]arr){intstartSumMax=0;intendSumMax=0;intstartIndex=0;intendIndex=0;intmax=0;for(inti=0;i<arr.length;i++ 阅读全文
posted @ 2011-06-01 11:31 不惜 阅读(162) 评论(0) 推荐(0) 编辑