-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathLeetCode#121.cc
More file actions
38 lines (34 loc) · 1.07 KB
/
LeetCode#121.cc
File metadata and controls
38 lines (34 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class Solution {
public:
int maximalRectangle(vector<vector<char> > &mat) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int N = mat.size();
if(N==0) return 0;
int M = mat[0].size();
if(M==0) return 0;
vector<vector<int> > sum;
for(int i=0;i<N;i++)
sum.push_back(vector<int>(M,0));
for(int i=0;i<N;i++){
sum[i][M-1] = mat[i][M-1]=='1' ? 1:0;
for(int j=M-2;j>=0;j--)
if(mat[i][j]=='0') sum[i][j]=0;
else sum[i][j] = sum[i][j+1]+1;
}
int ret = 0;
for(int k=0;k<M;k++){
for(int i=0;i<N;i++){
int _min = sum[i][k];
if(_min==0) continue;
for(int j=i;j<N;j++){
_min = min(sum[j][k],_min);
if(_min==0) break;
if((j-i+1)*_min > ret)
ret = (j-i+1)*_min;
}
}
}
return ret;
}
};