下面这段代码,不断的提示溢出。应该是两个for循环处溢出了。但是不清楚为什么。
烦请各位朋友帮忙答个疑解个惑。
class Solution {
public:
int maxArea(int h, int w, vector<int>& horizontalCuts, vector<int>& verticalCuts)
{
sort(horizontalCuts.begin(), horizontalCuts.end());
sort(verticalCuts.begin(), verticalCuts.end());
int length_w = verticalCuts.size();
int length_h = horizontalCuts.size();
int max_w = verticalCuts[0], max_h = horizontalCuts[0];
int i = 1, j = 1;
for(i = 1; i < length_h; i++)
max_h = max(horizontalCuts[i] - horizontalCuts[i - 1], max_h);
for(j = 1; j <= length_w; j++)
max_w = max(verticalCuts[i] - verticalCuts[i - 1], max_w);
max_w = max(w - verticalCuts[length_w - 1], max_w);
max_h = max(h - horizontalCuts[length_h - 1], max_h);
return (((long long)(max_h * max_w)) % mod);
}
private:
static constexpr int mod = 1e9 + 7;
};