8ms java solution, beats 96.89%


  • 0
    T
    class Solution {
        int ret;
        public int maximalSquare(char[][] matrix) {
            for(int i=0;i<matrix.length;i++){
                for(int j=0;j<matrix[0].length;j++){
                    verify(matrix,i,j,0);
                }
            }
            return ret;
        }
        public void verify(char[][] matrix,int i,int j,int num){
            if(i+num==matrix.length || j+num==matrix[0].length) return;
            for(int k=0;k<=num;k++){
                if(matrix[i+num][j+k]!='1') return;
                if(matrix[i+k][j+num]!='1') return;
            }
            ret=Math.max(ret,(num+1)*(num+1));
            verify(matrix,i,j,num+1);
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.