LeetCode 53. Maximum Subarray
2017-02-11 09:25
393 查看
description:
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.
非常简单的一道题目。
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.
非常简单的一道题目。
public class Solution { public int maxSubArray(int[] nums) { if (nums == null || nums.length == 0) { return 0; } int sum = 0; int maxValue = Integer.MIN_VALUE; for (int i = 0; i < nums.length; i++) { sum += nums[i]; maxValue = Math.max(maxValue, sum); sum = Math.max(0, sum); } return maxValue; } }
相关文章推荐
- leetcode:53. Maximum Subarray
- Leetcode 53. Maximum Subarray
- Leetcode 53. Maximum Subarray
- leetcode--3,Longest Substring Without Repeating Characters &&53. Maximum Subarray&&String.valueOf()
- LeetCode 53. Maximum Subarray
- [LeetCode] 53. Maximum Subarray
- 个人记录-LeetCode 53. Maximum Subarray
- 【一天一道LeetCode】#53. Maximum Subarray
- LeetCode 53. Maximum Subarray
- [leetcode] 53. Maximum Subarray 解题报告
- leetcode - 53. Maximum Subarray
- LeetCode53. Maximum Subarray
- LeetCode53. Maximum Subarray 动态规划和分治法
- leetcode: 53. Maximum Subarray
- leetcode 53. Maximum Subarray
- leetcode_53. Maximum Subarray
- LeetCode 53. Maximum Subarray
- [勇者闯LeetCode] 53. Maximum Subarray
- leetcode 53. Maximum Subarray
- 【LeetCode】53. Maximum Subarray