DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

ZeeshanAli-0704
ZeeshanAli-0704

Posted on

Maximum Subarray: LeetCode

var maxSubArray = function(nums) {

  let max = nums[0];
  let maxEnding = nums[0];
  for (let i = 1; i < nums.length; i++) {
    maxEnding = Math.max(maxEnding + nums[i], nums[i]);
    max = Math.max(maxEnding, max);
  }
  return max;
};
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

πŸ€” Did you know?

Β 
🌚 Dark mode is available in Settings.