From faad7dfd2bc8c62e41fa2cfa3a4387958d744f5c Mon Sep 17 00:00:00 2001 From: ductnn Date: Tue, 12 Dec 2023 08:52:13 +0700 Subject: [PATCH] add sol --- .../maximumProductofTwoElementsinanArray.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 leetcode/1464.MaximumProductofTwoElementsinanArray/maximumProductofTwoElementsinanArray.go diff --git a/leetcode/1464.MaximumProductofTwoElementsinanArray/maximumProductofTwoElementsinanArray.go b/leetcode/1464.MaximumProductofTwoElementsinanArray/maximumProductofTwoElementsinanArray.go new file mode 100644 index 0000000..433d1fc --- /dev/null +++ b/leetcode/1464.MaximumProductofTwoElementsinanArray/maximumProductofTwoElementsinanArray.go @@ -0,0 +1,16 @@ +package main + +import ( + "fmt" + "sort" +) + +func maxProduct(nums []int) int { + sort.Ints(nums) + return (nums[len(nums)-1] - 1) * (nums[len(nums)-2] - 1) +} + +func main() { + nums := []int{3, 4, 5, 2} + fmt.Println(maxProduct(nums)) +}