efficient python solution


  • 0
    F
        def maximumProduct(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            from operator import mul
    
            def product(arr):
                return reduce(mul, arr)
    
            max_nums, min_nums = heapq.nlargest(3, nums), heapq.nsmallest(2, nums)
            return max(product(max_nums), product(max_nums[:1] + min_nums))

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.