一周的气温在切片里(至少一天)。写 MinMax(temps),一次返回最低和最高两个值。
MinMax([]int{18, 25, 21})→(18, 25)MinMax([]int{7})→(7, 7)func MinMax(temps []int) (int, int)package main
func MinMax(temps []int) (int, int) {
low, high := temps[0], temps[0]
for _, t := range temps {
// 在这里写:比 low 低就换 low,比 high 高就换 high
}
return low, high
}
写好了先点「运行」试试示例,没问题再点「提交」。