Created
July 7, 2021 07:51
-
-
Save mocyuto/4460b87b8ef620315f8041bfebcb679e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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