JavaScript solution


  • 0
    L
    function maxSubArray(A) {
      var prev = 0;
      var max = -Number.MAX_VALUE;
    
      for (var i = 0; i < A.length; i++) {
        prev = Math.max(prev + A[i], A[i]);
        max = Math.max(max, prev);
      }
      return max;
    }

Log in to reply
 

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