Algorithms—53.Maximum Subarray

原创 2015年07月09日 11:15:47

思路:最大子数组

public class Solution {
    public int maxSubArray(int[] nums) {
        int sum=0;
        int answer=nums[0];
        for (int i = 0; i < nums.length; i++) {
			sum+=nums[i];
			if (sum>answer) {
				answer=sum;
			}
			if (sum<0) {
				sum=0;
			}
		}
    	return answer;
    }
}


耗时:368ms,中游


版权声明:本文为博主原创文章,未经博主允许不得转载。

Starting with Algorithms(Part3)--The maximum-subarray problem

The maximum-subarray problem Giving an array A[1..n] which contains some negative numbers, then fin...

leetCode 53.Maximum Subarray (子数组的最大和) 解题思路方法

Maximum Subarray  Find the contiguous subarray within an array (containing at least one number) w...

LeetCode(53) Maximum Subarray

题目Find the contiguous subarray within an array (containing at least one number) which has the larges...
  • fly_yr
  • fly_yr
  • 2015年09月05日 20:35
  • 765

leetcode刷题之旅——53. Maximum Subarray

本周写的第二道分治算法的题目,因为上次选择的是一道easy的题目,为了提升自己,这次选择了一道middle难度的题目。虽然这道题目是middle的,但是我还是想了很长时间。其实这道题目可以用动态规划直...

LeetCode 53. Maximum Subarray(dynamic programming)

题目链接:https://leetcode.com/problems/maximum-subarray/ 题目描述: Find the contiguous subarray within an ...

[LeetCode]53.Maximum Subarray

【题目】 Find the contiguous subarray within an array (containing at least one number) which has the l...

53.Maximum Subarray | LeetCode 解题思路

本题来源于LeetCode devide and conquer题库,难度easy。

Leetcode53 Maximum Subarray

Maximum Subarray Find the contiguous subarray within an array (containing at least one number) whi...

Leetcode题解 - 53. Maximum Subarray

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

[LeetCode] 53. Maximum Subarray

[LeetCode] 53. Maximum Subarray(Medium) 分治算法实践
  • zhao_tw
  • zhao_tw
  • 2016年09月20日 21:21
  • 112
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Algorithms—53.Maximum Subarray
举报原因:
原因补充:

(最多只允许输入30个字)