Leetcode Note: Go - Maximum Product Difference Between Two Pairs

Maximum Product Difference Between Two Pairs - LeetCode
https://leetcode.com/problems/maximum-product-difference-between-two-pairs/

  • Go 言語で取り組んだメモ

回答

Simple solution and easy you understand - Maximum Product Difference Between Two Pairs - LeetCode
https://leetcode.com/problems/maximum-product-difference-between-two-pairs/solutions/2677771/simple-solution-and-easy-you-understand/

func maxProductDifference(nums []int) int {
    sort.Ints(nums)
    
    left := nums[0] * nums[1]
    rigth := nums[len(nums)-1] * nums[len(nums)-2]
    
    res := rigth - left
    
    return res
}