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,中游


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

相关文章推荐

LeetCode(53) Maximum Subarray

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

leetcode刷题之旅——53. Maximum Subarray

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

53. Maximum Subarray

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

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...

53. Maximum Subarray

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

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) 分治算法实践
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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