> For the complete documentation index, see [llms.txt](https://jenhsuan.gitbook.io/algorithm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jenhsuan.gitbook.io/algorithm/leetcode/152.-maximum-product-subarray.md).

# 152. Maximum Product Subarray

## 1.問題

![](/files/-LabstyFN8P4aJIPPJsL)

## 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;
    }
};
```

##
