Kodewick
开始学 →
基础←→0 / 70

这一局打得怎样

#047基础函数切片约 3 分钟

一局游戏有好几轮(至少一轮),points 是每轮的得分。写 Rounds(points),一次返回总分和得分最高的那一轮。

示例
Rounds([]int{4, 9, 2})→(15, 9)
Rounds([]int{7})→(7, 7)
函数func Rounds(points []int) (int, int)
main.go
package main

func Rounds(points []int) (int, int) {
	total, best := 0, points[0]
	for _, p := range points {
		// 在这里写:加进 total;比 best 大就换掉 best
	}
	return total, best
}
Ctrl + Enter 也能运行
结果

写好了先点「运行」试试示例,没问题再点「提交」。