Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- public int maximalSquare(char[][] matrix) {
- if(matrix.length == 0) return 0;
- int row = matrix.length;
- int col = matrix[0].length;
- int maxSum = 0;
- int[][] dp = new int[row + 1][col + 1];
- for(int i = 1; i < row + 1; i ++){
- for(int j = 1; j < col + 1; j ++){
- dp[i][j] = 0;
- if(matrix[i-1][j-1] == '1'){
- int x = Math.min(dp[i-1][j], dp[i][j-1]);
- dp[i][j] = Math.min(x, dp[i-1][j-1]) + 1;
- //System.out.println("cacat");
- }
- if(dp[i][j] > maxSum)
- maxSum = dp[i][j];
- }
- }
- return maxSum * maxSum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement