My simple Java solution beats 94.38%


  • 1
    H
    public int maxSubArray(int[] nums) {
            int n = nums.length, max = nums[0];
            for(int i = 1; i < n; i++){
                int x = nums[i - 1];
                nums[i] = nums[i] + (x > 0 ? x: 0);
                max = Math.max(max, nums[i]);
            }
            
            return max;
    
        }
    
    

Log in to reply
 

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