C++ solution using sort.


  • 0
    T
    class Solution {
    public:
        int maximumProduct(vector<int>& nums) {
            std::sort(nums.begin(), nums.end());
            int n = nums.size();
            
            return max(nums[0] * nums[1] * nums[n - 1], nums[n - 1] * nums[n - 2] * nums[n - 3]);
        }
    };
    

Log in to reply
 

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