Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int maximalSquare(vector<vector<char>>& mat) {
- int rows = mat.size(), cols = mat[0].size();
- int len = 0, dp[rows][cols];
- for(int i=0; i<rows; i++){
- for(int j=0; j<cols; j++){
- dp[i][j] = (mat[i][j] == '1') ? 1 : 0;
- if(dp[i][j] && i && j){
- int sz = min({dp[i-1][j], dp[i][j-1], dp[i-1][j-1]});
- dp[i][j] = sz+1;
- }
- len = max(len, dp[i][j]);
- }
- }
- return len*len;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement