# 152. Maximum Product Subarray

## 1.問題

![](https://901207480-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGKoChvN9am4__HCIRK%2F-LabsmyqkwoMvDQPe0OL%2F-LabstyFN8P4aJIPPJsL%2Fimage.png?alt=media\&token=dbc311b0-4424-40e7-b022-e8087509c4fe)

## 2.想法&#x20;

## 3.程式碼

```
class Solution {
public:
    int maxProduct(vector<int>& nums) {
        if (nums.size() == 0) {
            return 0;
        }
        
        vector<int>res;
        int size = nums.size(), maxProd = INT_MIN, start = 0, end = 0;
        for (int i = 0; i < size; i++) {
            int prod = 1;
            for (int j = i; j >=0; j--) {
                prod *= nums[j];
                maxProd = max(maxProd, prod);
            }
        }
        
        
        return maxProd;
    }
};
```

##
