Skip to content

Instantly share code, notes, and snippets.

@manish-manghwani
Created September 27, 2020 06:31
Show Gist options
  • Select an option

  • Save manish-manghwani/9c97ebd3c127508fb06efb4e8d8b3404 to your computer and use it in GitHub Desktop.

Select an option

Save manish-manghwani/9c97ebd3c127508fb06efb4e8d8b3404 to your computer and use it in GitHub Desktop.
function maxSubArray(nums: number[]): number {
let current_max = nums[0]
let global_max = nums[0]
if(nums.length == 1) {
return current_max;
}
for (let i= 1 ; i<nums.length ; i++) {
current_max = current_max + nums[i] >= nums[i] ? current_max + nums[i] : nums[i]
global_max = current_max > global_max ? current_max : global_max
}
return global_max
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment