-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path221.cpp
More file actions
78 lines (64 loc) · 1.51 KB
/
Copy path221.cpp
File metadata and controls
78 lines (64 loc) · 1.51 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <vector>
#include <iostream>
using namespace std;
class Solution {
public:
int maximalSquare(vector<vector<char>>& matrix) {
if(matrix.size() == 0)return 0;
int n = matrix.size();
int o = matrix[0].size();
vector< vector<int> > e;
e.resize(n);
for(int i = 0; i < n; ++i)
{
e[i].resize(o);
}
int ma = 0;
for(int i = 0; i < o; ++i)
{
e[0][i] = matrix[0][i] - '0';
if(e[0][i] == 1)ma = 1;
}
for(int i = 0; i < n; ++i)
{
e[i][0] = matrix[i][0] - '0';
if(e[i][0] == 1)ma = 1;
}
int l = 0, k = 0, m = 0;
for(int i = 1; i < n; ++i)
{
for(int j = 1; j < o; ++j)
{
if(matrix[i][j] != '1')continue;
l = e[i-1][j-1];
for(k = i - 1; k > i - 1 - l; --k)
{
if(matrix[k][j] != '1')break;
}
for(m = j - 1; m > j - 1 - l; --m)
{
if(matrix[i][m] != '1')break;
}
e[i][j] = i - k < j - m ? i - k : j - m;
if(e[i][j] > ma)ma = e[i][j];
}
}
return ma * ma;
}
};
int main()
{
Solution s;
/*
int n, t;
vector<int> vi;
cin >> n;
for(int i = 0; i < n; ++i)
{
cin >> t;
vi.push_back(t);
}
cout << s.maxProfit(vi) << endl;
*/
return 0;
}