1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
// @Title: 三个数的最大乘积 (Maximum Product of Three Numbers)
// @Author: 15816537946@163.com
// @Date: 2021-01-20 23:42:46
// @Runtime: 80 ms
// @Memory: 6.6 MB
func maximumProduct(nums []int) int {
	sort.Ints(nums)
	n := len(nums)
	return max(nums[0]*nums[1]*nums[n-1], nums[n-3]*nums[n-2]*nums[n-1])
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}