Two lines O(n) solution in Java


  • 0
    C

    ...
    int index = 0, max = nums[0], pre = nums[0];
    while(++index < nums.length) max = Math.max(max, pre = Math.max(nums[index], pre + nums[index]));
    ...


Log in to reply
 

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