Java Simple Solution


  • 0
    E

    Same approach as others have discussed

    public class Solution {
        public int maxSubArray(int[] nums) {
            if(nums.length==0){
               return 0;
            }
            int max=nums[0];
            for(int i=1;i<nums.length;i++){
               if(nums[i-1]>0){
                  nums[i]=nums[i-1]+nums[i];
               }
               if(max<nums[i]){
                  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.