设为首页 加入收藏

TOP

[LeetCode]Maximum Subarray
2015-07-20 17:31:34 来源: 作者: 【 】 浏览:3
Tags:LeetCode Maximum Subarray

Find the contiguous subarray within an array (containing at least one number) which has the largest sum.

For example, given the array [?2,1,?3,4,?1,2,1,?5,4],
the contiguous subarray [4,?1,2,1] has the largest sum = 6.

click to show more practice.

More practice:

If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.

o(n)解法

public class Solution {
    public int maxSubArray(int[] A) {
        if(A.length == 1) return A[0];
        int max = A[0];
        int sum = A[0];
        for(int i = 1;i
  
   







】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 4405 Aeroplane chess (概率d.. 下一篇BZOJ 1040 ZJOI 2008 骑士 基环树..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·About - Redis (2025-12-26 08:20:56)
·Redis: A Comprehens (2025-12-26 08:20:53)
·Redis - The Real-ti (2025-12-26 08:20:50)
·Bash 脚本教程——Li (2025-12-26 07:53:35)
·实战篇!Linux shell (2025-12-26 07:53:32)