一週的氣溫在切片裡(至少一天)。寫 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
}
寫好了先點「執行」試試示例,沒問題再點「提交」。