Your browser (Internet Explorer 6) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browser.

LeetCode: Maximum Subarray (14ms)

public class Solution {
    public int maxSubArray(int[] nums) {
        int maxSoFar=nums[0], maxEndingHere=nums[0];
        for (int i = 1; i < nums.length; ++i){
        	maxEndingHere = Math.max(maxEndingHere + nums[i], nums[i]);
        	maxSoFar = Math.max(maxSoFar, maxEndingHere);	
        return maxSoFar;

comments powered by Disqus