```
class Solution {
public:
int maxProduct(vector<int>& nums) {
int length = nums.size();
int a = nums[0], b = nums[0];
int max_prod = nums[0];
for(int i = 1; i < length; i++) {
int ta = a, tb =b;
a = min(min(nums[i], tb * nums[i]), ta * nums[i]);
b = max(max(nums[i], tb * nums[i]), ta * nums[i]);
max_prod = max(b, max_prod);
}
return max_prod;
}
};
```