File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution {
2+ public:
3+ int maximalSquare (vector<vector<char >>& matrix) {
4+
5+ if (matrix.size () == 0 ) return 0 ;
6+
7+ int m = matrix.size (), n = matrix[0 ].size ();
8+ vector<vector<int >> globalSum (m + 1 , vector<int >(n + 1 ));
9+
10+ /* for(auto i : globalSum){
11+ for(auto j: i){
12+ cout<<j<<" ";
13+ }
14+ cout<<"\n";
15+ }*/
16+
17+ /* for(int i=0; i<m; i++) // first column
18+ globalSum[i][0] = matrix[i][0] - '0';
19+
20+ for(int i=0; i<n; i++) //first row
21+ globalSum[0][i] = matrix[0][i] - '0';*/
22+
23+ auto globalMax = 0 ;
24+ for (int i=1 ; i<m+1 ; i++){
25+ for (int j=1 ; j<n+1 ; j++){
26+ globalSum[i][j] = matrix[i-1 ][j-1 ] == ' 0' ? 0 :
27+ (min (globalSum[i][j-1 ], min (globalSum[i-1 ][j-1 ], globalSum[i-1 ][j])) + 1 );
28+ globalMax = max (globalMax, globalSum[i][j]);
29+ }
30+ }
31+
32+ cout<<" \n " ;
33+ for (auto i:globalSum){
34+ for (auto j:i){
35+ cout<<j<<" " ;
36+ }
37+ cout<<" \n " ;
38+ }
39+
40+ return globalMax * globalMax;
41+ // return 0;
42+ }
43+ };
You can’t perform that action at this time.
0 commit comments