forked from Nimesh-Srivastava/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0221.cpp
More file actions
29 lines (21 loc) · 795 Bytes
/
0221.cpp
File metadata and controls
29 lines (21 loc) · 795 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
class Solution {
public:
int maximalSquare(vector<vector<char>>& matrix) {
int row = matrix.size();
int col = matrix[0].size();
vector<vector<int>> dp(row + 1, vector<int>(col + 1, 0));
int result = 0;
for(int i = 1; i <= row; i++){
for(int j = 1; j <= col; j++){
if(matrix[i - 1][j - 1] == '0')
dp[i][j] = 0;
else{
int minVal = min(dp[i][j - 1], dp[i - 1][j - 1]);
dp[i][j] = min(dp[i - 1][j], minVal) + 1;
}
result = max(result, dp[i][j]);
}
}
return result * result;
}
};