You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
lavos/cap4/ex15.go

15 lines
299 B

package cap4
// Ex15 最大子段和
func Ex15(nums []int) int {
result := nums[0]
currMaxSum := nums[0]
n := len(nums)
for i := 1; i < n; i++ {
num := nums[i]
currMaxSum = max(currMaxSum+num, num)
result = max(result, currMaxSum)
}
return result
}