这道题十分不容易啊,做到半夜。

class Solution {
public:
static int cmp628(int a, int b)
{
return a > b;
} static int cmp628_2(int a, int b)
{
return abs(a) < abs(b);
} int maximumProduct(vector<int>& nums) {
const int N = ;
int Pos[N];
int Nag[N];
int Nor[N]; int i = , j = , k = ;
for (auto n : nums)
{
if (n >= )
{
Pos[i] = n;
i++;
}
else
{
Nag[j] = n;
j++;
}
Nor[k] = n;
k++;
} sort(Pos, Pos + i, cmp628);
sort(Nag, Nag + j);
sort(Nor, Nor + k, cmp628_2); int a = INT_MIN, b = INT_MIN, c = INT_MIN, d = INT_MIN, max = INT_MIN; //三正
if (i >= )
{
a = Pos[] * Pos[] * Pos[];
if (j >= )
{
b = Pos[] * Nag[] * Nag[];
}
}
else if (i >= )
{
a = Pos[] * Pos[] * Nag[];
if (j >= )
{
b = Pos[] * Nag[] * Nag[];
}
}
if (j >= )
{
c = Nag[] * Nag[] * Nag[];
if (i >= )
{
d = Nag[j - ] * Pos[] * Pos[];
}
else if (i == )
{
d = Nag[] * Nag[] * Pos[];
} }
else if (j >= )
{
c = Nag[] * Nag[] * Pos[];
if (i >= )
{
d = Nag[j - ] * Pos[] * Pos[];
}
else if (i == )
{
d = Nag[] * Nag[] * Pos[];
}
} if (max < a)
max = a;
if (max < b)
max = b;
if (max < c)
max = c;
if (max < d)
max = d; return max;
}
};
05-11 20:03