python, dp, faster than 98+%
If anyone doesn\'t understand my solution, comment.\n\n\nclass Solution:\n    def largest1BorderedSquare(self, grid: List[List[int]]) -> int:\n        \n       
If anyone doesn\'t understand my solution, comment.\n![image](https://assets.leetcode.com/users/images/b1ba9f24-c30b-4b60-a6ef-2b96cb931e95_1623235285.7297766.png)\n```\nclass Solution:\n    def largest1BorderedSquare(self, grid: List[List[int]]) -> int:\n        \n        width = len(grid[0])\n        height = len(grid)\n        \n        dp = [[(0, 0)] * width for x in range(height)]\n        \n        max_len = 0\n        for i in range(height):\n            for j in range(width):\n                if grid[i][j] == 0:\n                    dp[i][j] == (0, 0)\n                else:\n                    if max_len == 0: max_len = 1\n                    if i == 0 and j == 0: \n                        dp[i][j] = (1, 1)\n                    elif i == 0:\n                        dp[i][j] = (1, dp[i][j-1][1] + 1)\n                    elif j == 0:\n                        dp[i][j] = (dp[i-1][j][0] + 1, 1)\n                    else:\n                        dp[i][j] = (dp[i-1][j][0] + 1, dp[i][j-1][1] + 1) # height and width\n                        for k in range(max_len, min(dp[i][j])): # k+1 is side length of the square\n                            if dp[i-k][j][1] >= k + 1 and dp[i][j-k][0] >= k + 1:\n                                max_len = k+1\n        #print(dp)\n        return max_len * max_len\n```\nThe image below maybe help you understand the magic.\n![image](https://assets.leetcode.com/users/images/b3f26825-6387-4a7c-b9d3-089f4afcb353_1623235487.0529752.png)\n
['Dynamic Programming', 'Python', 'Python3']