Simple JAVA Solution, 4ms faster than 73%
\tclass Solution {\n\t\tpublic int largest1BorderedSquare(int[][] grid) {\n\t\t\tint n = grid.length, m = grid[0].length;\n\t\t\tint ans = 0;\n\t\t\tint[][] h =
\tclass Solution {\n\t\tpublic int largest1BorderedSquare(int[][] grid) {\n\t\t\tint n = grid.length, m = grid[0].length;\n\t\t\tint ans = 0;\n\t\t\tint[][] h = new int[n+1][m+1];\n\t\t\tint[][] v = new int[n+1][m+1];\n\t\t\tfor(int i=1;i<=n;i++){\n\t\t\t\tfor(int j=1;j<=m;j++){\n\t\t\t\t\tif(grid[i-1][j-1]==1){\n\t\t\t\t\t\tv[i][j] = 1+v[i-1][j];\n\t\t\t\t\t\th[i][j] = 1+h[i][j-1];\n\t\t\t\t\t\tint t = Math.min(v[i-1][j],h[i][j-1]);\n\t\t\t\t\t\tfor(int k=t;k>=0;k--){\n\t\t\t\t\t\t\tif(v[i][j-k]>=k+1&&h[i-k][j]>=k){\n\t\t\t\t\t\t\t\tans = Math.max(ans,k+1);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ans*ans;\n\t\t}\n\t}
['Java']