O(n) -constant space -clean


  • 0
    L
        int pMax = nums[0];
        int pMin = pMax;
        int gMax = pMax;
        for( int i = 1; i < nums.size(); i++)
        {
            int t1 = pMax * nums[i];
            int t2 = pMin * nums[i];
            pMax = max( t2, max( t1, nums[i] ) );
            pMin = min( t1, min( t2, nums[i] ) );
            gMax = max (gMax, pMax);
        }
        return gMax;

Log in to reply
 

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