Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int maximalSquare(char[][] matrix) {
- int rows = matrix.length;
- int cols = matrix[0].length;
- int[][] dp = new int[rows + 1][cols + 1];
- int maxsqlen = 0;
- for (int row = 1; row <= rows; row++) {
- for (int col = 1; col <= cols; col++) {
- if (matrix[row - 1][col - 1] == '1') {
- dp[row][col] = 1 + Math.min(
- dp[row - 1][col - 1],
- Math.min(dp[row - 1][col], dp[row][col - 1])
- );
- maxsqlen = Math.max(maxsqlen, dp[row][col]);
- }
- }
- }
- return maxsqlen * maxsqlen;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement