Share my Python solution

  • 2

    Sort the array, the maximum product happens in two situations:
    the last three or the first two with the last one.
    Here is the Python code!

    class Solution(object):
        def maximumProduct(self, nums):
            :type nums: List[int]
            :rtype: int
            return max(nums[-1]*nums[-2]*nums[-3], nums[0]*nums[1]*nums[-1])

  • 0


    ah this is so much more cleaner. I had the right idea but my code looked so messy, this is very clean!

Log in to reply

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