Maximum Product of Three Numbers (Leetcode 628)

Problem Link: https://leetcode.com/problems/maximum-product-of-three-numbers/

class Solution:
    def maximumProduct(self, nums: List[int]) -> int:
        
        nums.sort()
        ans=nums[-1]*nums[-2]*nums[-3]
        if(nums[0]<0 and nums[1]<0):
            ans=max(ans,nums[0]*nums[1]*nums[-1])
        
        return ans

Last updated