DeepRest

Maximal Square

Dec 17th, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. class Solution:
  2.     def maximalSquare(self, matrix: List[List[str]]) -> int:
  3.        
  4.         res = 0
  5.         for i in range(len(matrix)):
  6.             for j in range(len(matrix[0])):
  7.                 matrix[i][j] = int(matrix[i][j])
  8.                 if i > 0 and j > 0 and matrix[i][j] == 1:
  9.                     matrix[i][j] = min(matrix[i][j-1], matrix[i-1][j-1], matrix[i-1][j]) + 1
  10.                 res = max(res, matrix[i][j]**2)
  11.        
  12.         return res
Advertisement
Add Comment
Please, Sign In to add comment