Square with dp
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int largest1BorderedSquare(int[][] grid) {\n        int m=grid.length;\n        int n=grid[0].length;\n\t\t// rows[r][c] is the length of the line ended at [r,c] on row r\n        int[][] rows=new int[m][n];        \n\t\t// the length of the line ended at [r,c] on colume c\n        int[][] cols=new int[m][n];\n        int res=0;\n        for(int r=0;r<m;r++){\n            for(int c=0;c<n;c++){\n                if(grid[r][c]==0){\n                    rows[r][c]=0;\n                    cols[r][c]=0;\n                }else{\n                    rows[r][c]=c==0?1:rows[r][c-1]+1;\n                    cols[r][c]=r==0?1:cols[r-1][c]+1;\n                    if(res>=rows[r][c]||res>=cols[r][c]){\n                        continue;\n                    }\n                    res=Math.max(res,getD(rows,cols,r,c));\n                }\n            }\n        }\n        return res*res;\n    }\n    \n\t// get the dimension of the largest square which bottom-right point is [row,col]\n    private int getD(int[][] rows,int[][] cols,int row,int col){\n        int len=Math.min(rows[row][col],cols[row][col]);\n        for(int i=len-1;i>=0;i--){\n            if(rows[row-i][col]>i && cols[row][col-i]>i){\n                return i+1;\n            }\n        }\n        return 1;\n    }\n}\n```
['Java']