Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Dec 18, 2023
1 parent 86561f9 commit 492e4d5
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 492e4d5

Please sign in to comment.