class Solution {
public:
    /*
        dp(i)表示以nums[i]结尾的最长连续子串
        f(i)表示最大,g(i)表示最小
        if(nums[i] > 0) {
           f(i) = max(num(i), f(i-1) * nums[i])
           f(i) = min(num(i), g(i-1) * nums[i])
        } else {
           
        }
    */
    double maxProduct(vector<double>& nums) {
       int n = nums.size();
       double res = nums[0];
       vector<double>f(n, 0), g(n, 0);
       f[0] = nums[0], g[0] = nums[0];  // 初始化
       for(int i = 1; i < n; i++)
       {
           if(nums[i] > 0) {
               f[i] = max(nums[i], f[i-1] * nums[i]);
               g[i] = min(nums[i], g[i-1] * nums[i]);
           } else {
               f[i] = max(nums[i], g[i-1] * nums[i]);
               g[i] = min(nums[i], f[i-1] * nums[i]);
           }
           res = max(res, f[i]);         
       }         
       return res;         
    }
};