Files
LeetCode-Go/leetcode/1464.Maximum-Product-of-Two-Elements-in-an-Array/1464. Maximum Product of Two Elements in an Array.go
2020-08-12 22:17:47 +08:00

15 lines
244 B
Go

package leetcode
func maxProduct(nums []int) int {
max1, max2 := 0, 0
for _, num := range nums {
if num >= max1 {
max2 = max1
max1 = num
} else if num <= max1 && num >= max2 {
max2 = num
}
}
return (max1 - 1) * (max2 - 1)
}