JasonChang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 1 public class Solution {
 2     public int maxSubArray(int[] A) {
 3         // IMPORTANT: Please reset any member data you declared, as
 4         // the same Solution instance will be reused for each test case.
 5         int result = Integer.MIN_VALUE;
 6         int curSum = 0;
 7         for(int i = 0; i < A.length; i++){
 8             curSum += A[i];
 9             if(curSum > result){
10                 result = curSum;
11             }
12             if(curSum < 0){
13                 curSum = 0;
14             }
15         }
16         
17         return result;
18     }
19 }

 

posted on 2013-11-19 05:42  JasonChang  阅读(171)  评论(0编辑  收藏  举报