-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.cpp
More file actions
36 lines (34 loc) · 998 Bytes
/
program.cpp
File metadata and controls
36 lines (34 loc) · 998 Bytes
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
#include "../include/pre.h"
// Got "Runtime error" with leetcode but run properly locally
// I don't know whats wrong with this function
int maximalSquare(vector<vector<char>>& matrix)
{
if (matrix.size() == 0) return 0;
auto M = matrix.size();
auto N = matrix[0].size();
vector<vector<int>> p (M + 1, vector<int> (N + 1, 0));
int maxSideLength = 0;
for (int i = 1; i <= M; i++) {
for (int j = 1; j <= N; j++) {
if (matrix[i-1][j-1] == '1') {
p[i][j] = std::min(std::min(p[i][j-1], p[i-1][j]), p[i-1][j-1]) + 1;
maxSideLength = std::max(maxSideLength, p[i][j]);
}
}
}
return maxSideLength * maxSideLength;
}
int main()
{
// vector<vector<char>> t {
// {'0',},
// };
vector<vector<char>> t {
{'1','0','1','0','0',},
{'1','0','1','1','1',},
{'1','1','1','1','1',},
{'1','0','0','1','0',},
};
cout << maximalSquare(t);
return 0;
}