牛客题霸 NC19 子数组的最大累加和问题
生活随笔
收集整理的這篇文章主要介紹了
牛客题霸 NC19 子数组的最大累加和问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://www.nowcoder.com/practice/554aa508dd5d4fefbf0f86e5fe953abd
解決方案
Go
func maxsumofSubarray(arr []int) int {// write code herecur, Max := 0, 0for _, a := range arr {cur = max(cur+a, a)Max = max(cur, Max)}return Max }func max(a, b int) int {if a > b {return a}return b }func main() {maxsumofSubarray([]int{1, -2, 3, 5, -2, 6, -1}) }參考文章
總結
以上是生活随笔為你收集整理的牛客题霸 NC19 子数组的最大累加和问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Go——从文件路径解析解析GAVC坐标解
- 下一篇: 牛客题霸 NC20 数字字符串转化成IP