Maximum Subarray


  • 0
    V

    class Solution {
    public int maxSubArray(int[] nums) {
    if(nums == null || nums.length == 0)
    return 0;

            int temp = nums[0];
            int max = temp;
            for(int i = 1; i < nums.length; i++) {
            	if(temp < 0) 
            		temp = nums[i];
            	else 
            		temp += nums[i];
            	max = Math.max(max, temp);
        
    }
         return max; 
    

    }
    }


Log in to reply
 

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