Skip to content

Instantly share code, notes, and snippets.

@mocyuto
Created July 7, 2021 07:51
Show Gist options
  • Save mocyuto/4460b87b8ef620315f8041bfebcb679e to your computer and use it in GitHub Desktop.
Save mocyuto/4460b87b8ef620315f8041bfebcb679e to your computer and use it in GitHub Desktop.
func maxSubArray(nums []int) int {
m := nums[0]
tmpSum := 0
for _, n := range nums {
if tmpSum < 0 {
tmpSum = 0
}
tmpSum += n
if m < tmpSum {
m = tmpSum
}
}
return m
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment