my simple java code


  • 0
    A

    class Solution {
    public int maxSubArray(int[] nums) {

        int size = nums.length;
        int max_so_far = Integer.MIN_VALUE ;
        int sum  = 0;
        for(int i = 0 ; i < size ; i++)
        {
            sum = sum + nums[i];
            
            if(max_so_far < sum)
            {
                max_so_far = sum;
            }
            if(sum < 0)
            {
                sum  = 0;
            }
           
       }
         return max_so_far;
        
    }
    

    }


Log in to reply
 

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