From 492e4d5954a0ce39bc8a9a38a3ac1d97c74a6ef3 Mon Sep 17 00:00:00 2001 From: ductnn Date: Mon, 18 Dec 2023 09:41:16 +0700 Subject: [PATCH] add sol --- .../maximumProductDifferenceBetweenTwoPairs.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 leetcode/1913.MaximumProductDifferenceBetweenTwoPairs/maximumProductDifferenceBetweenTwoPairs.go diff --git a/leetcode/1913.MaximumProductDifferenceBetweenTwoPairs/maximumProductDifferenceBetweenTwoPairs.go b/leetcode/1913.MaximumProductDifferenceBetweenTwoPairs/maximumProductDifferenceBetweenTwoPairs.go new file mode 100644 index 0000000..a6738da --- /dev/null +++ b/leetcode/1913.MaximumProductDifferenceBetweenTwoPairs/maximumProductDifferenceBetweenTwoPairs.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + "sort" +) + +func maxProductDifference(nums []int) int { + sort.Ints(nums) + n := len(nums) + + return (nums[n-1] * nums[n-2]) - (nums[0] * nums[1]) +} + +func main() { + nums := []int{4, 2, 5, 9, 7, 4, 8} + fmt.Println(maxProductDifference(nums)) +}