设为首页 加入收藏

TOP

[LeetCode]Maximum Subarray
2015-07-20 17:31:34 来源: 作者: 【 】 浏览:2
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 骑士 基环树..

评论

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

·在 Redis 中如何查看 (2025-12-26 03:19:03)
·Redis在实际应用中, (2025-12-26 03:19:01)
·Redis配置中`require (2025-12-26 03:18:58)
·Asus Armoury Crate (2025-12-26 02:52:33)
·WindowsFX (LinuxFX) (2025-12-26 02:52:30)