Skip to content

Instantly share code, notes, and snippets.

@ms314006
Last active February 21, 2020 14:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ms314006/6ad8b2d1f7612e8d4bd33ff4fab44bc0 to your computer and use it in GitHub Desktop.
var maxSubArray = function(nums) {
let currentSum = maxSum = nums[0];
for(let i = 1; i < nums.length; i += 1) {
currentSum += nums[i];
if (currentSum < nums[i]) {
currentSum = nums[i];
}
if (currentSum > maxSum) {
maxSum = currentSum;
}
}
return maxSum;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment