Maximum Product of Three Numbers Solutions in PythonNumber 628Difficulty EasyAcceptance 47.1%Link LeetCodeOther languages GoSolutionsPython solution by haoel/leetcode# simply find the three largest and two smallest# Method 1: sortdef maximumProduct(self, nums): nums.sort() return max(nums[0] * nums[1] * nums[-1], nums[-1] * nums[-2] * nums[-3]) # Method 2: using heapq, O(n) timedef maximumProduct(self, nums): import heapq a, b = heapq.nlargest(3, nums), heapq.nsmallest(2, nums) return max(a[0] * a[1] * a[2], a[0] * b[0] * b[1])# simply find the three largest and two smallest # Method 1: sort def maximumProduct(self, nums): nums.sort() return max(nums[0] * nums[1] * nums[-1], nums[-1] * nums[-2] * nums[-3]) # Method 2: using heapq, O(n) time def maximumProduct(self, nums): import heapq a, b = heapq.nlargest(3, nums), heapq.nsmallest(2, nums) return max(a[0] * a[1] * a[2], a[0] * b[0] * b[1])