Simple and clear 7 lines O(n) solution

  • 0
    public int MaxSubArray(int[] nums) 
            int sum =0;
            int maxSum = int.MinValue;
            for(int i=0; i < nums.Length; i++)
                sum+= nums[i];
                sum = Math.Max(nums[i], sum);
                maxSum = Math.Max(maxSum, sum);
            return maxSum;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.