package main
import "fmt"
func max(vals...int) int {
var max int
for _, val := range vals {
if val > max {
max = val
}
}
return max
}
func min(vals...int) int {
var min int
for _, val := range vals {
if min == 0 || val <= min {
min = val
}
}
return min
}
func main() {
val := []int{15,77,57,238,54,108}
fmt.Println(max(val...)) // "238"
fmt.Println(min(val...)) // "15"
}
有疑问加站长微信联系(非本文作者)