首页 > 其他 > 详细

53 Maximum Subarray

时间:2018-08-10 15:14:13      阅读:168      评论:0      收藏:0      [点我收藏+]
53 Maximum Subarray


https://www.youtube.com/watch?v=7J5rs56JBs8



class Solution {
    public int maxSubArray(int[] nums) {
      int[] result = new int[nums.length];
      result[0] = nums[0];
      for(int i = 1; i < nums.length; i++){
        result[i] = result[i-1] > 0 ? result[i-1] + nums[i] : nums[i];
      }
      int max = Integer.MIN_VALUE;
      for(int i = 0; i < nums.length; i++){
        max = Math.max(result[i], max);
      }
      return max;
        
    }
}

 

53 Maximum Subarray

原文:https://www.cnblogs.com/tobeabetterpig/p/9454838.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!