今天复习以前的
干发现这个怎么加了一个test case==
[0,10,10,10,10,10,10,10,10,10,-10,10,10,10,10,10,10,10,10,10,0]
以前写的都会overflow
刚刚是直接用python噜过去了
但看解答C++好像可以直接用double== 点点点
int maxProduct(vector<int>& nums) {
double dp_neg = 1;
double dp_pos = 1;
double ans = -DBL_MAX;
for(auto n : nums) {
double tmp_neg = dp_neg * n;
double tmp_pos = dp_pos * n;
ans = max({ans, (double)n, tmp_neg, tmp_pos});
dp_neg = min({1.0, (double)n, tmp_neg, tmp_pos});
dp_pos = max({1.0, (double)n, tmp_neg, tmp_pos});
}
return (int)ans;
}