Created
April 27, 2020 15:09
-
-
Save SuryaPratapK/f3b0f874b123bac74a301bbac9bbb04e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int maximalSquare(vector<vector<char>>& matrix) { | |
int rows = matrix.size(); | |
if(rows==0) | |
return 0; | |
int cols = matrix[0].size(); | |
vector<vector<int>> dp(rows+1,vector<int>(cols+1,0)); | |
int largest = 0; | |
for(int i=1;i<=rows;++i) | |
{ | |
for(int j=1;j<=cols;++j) | |
{ | |
if(matrix[i-1][j-1]=='1') | |
{ | |
dp[i][j] = 1 + min(dp[i-1][j],min(dp[i][j-1],dp[i-1][j-1])); | |
if(largest < dp[i][j]) | |
largest = dp[i][j]; | |
} | |
} | |
} | |
return largest*largest; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Java Solution
`
`