Skip to content

Instantly share code, notes, and snippets.

@mAlishera
Last active January 16, 2020 15:54
Show Gist options
  • Save mAlishera/a0159d81958c6ba9afbe1ba5720c83c9 to your computer and use it in GitHub Desktop.
Save mAlishera/a0159d81958c6ba9afbe1ba5720c83c9 to your computer and use it in GitHub Desktop.
4 ms 3.3 MB
func maxSubArray(nums []int) int {
if len(nums) <= 0 {
return 0
}
max := nums[0]
for i := 1; i < len(nums); i++ {
if nums[i-1] > 0 {
nums[i] += nums[i-1]
}
if nums[i] > max {
max = nums[i]
}
}
return max
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment