01-复杂度1 最大子列和问题(Go语言)
作者:互联网
点击查看代码
package main
import "fmt"
func main() {
// 输入
var n int
fmt.Scanf("%d", &n)
inputs := make([]int, 0, n)
for i := 0; i < n; i++ {
var temp int
fmt.Scanf("%d", &temp)
inputs = append(inputs, temp)
}
max := 0
sum := 0
for _, input := range inputs {
sum += input
if sum > max {max = sum}
if sum < 0 {sum = 0}
}
fmt.Print(max)
}
标签:inputs,01,temp,int,max,fmt,sum,Go,复杂度 来源: https://www.cnblogs.com/burndust/p/16390893.html