easy understand python DP 160ms
\nclass Solution:\n    def largest1BorderedSquare(self, grid: List[List[int]]) -> int:\n        M,N,count=len(grid),len(grid[0]),0\n        dp=[[[0,0]for _ in r
```\nclass Solution:\n    def largest1BorderedSquare(self, grid: List[List[int]]) -> int:\n        M,N,count=len(grid),len(grid[0]),0\n        dp=[[[0,0]for _ in range(N+1)]for _ in range(M+1)]\n        for i in range(1,M+1):\n            for j in range(1,N+1):\n                if grid[i-1][j-1]==1:\n                    dp[i][j][0],dp[i][j][1]=dp[i-1][j][0]+1,dp[i][j-1][1]+1\n                    for k in range(min(dp[i][j][0],dp[i][j][1]),count,-1):\n                        if min(dp[i-k+1][j][1],dp[i][j-k+1][0])>=k:\n                            count=max(count,k)\n                            break\n        return count**2\n```
['Dynamic Programming', 'Python']