Simple java solution (15ms)


  • 0
    S

    public class Solution {
    public int maxSubArray(int[] nums) {
    int max =0;
    int result=nums[0];
    for(int i=0;i<nums.length;i++){
    max+=nums[i];
    if(nums[i]>max){max= nums[i];}
    if(max>result){result= max;}
    }
    return result;
    }
    }


Log in to reply
 

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