Участник:Ковальков Антон М05-903б/Maximal Square

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/maximal-square/

Python3

class Solution:
    def maximalSquare(self, matrix: List[List[str]]) -> int:
        m = 0
        a = [[0 for j in range(len(matrix[0]))] for i in range(len(matrix))]
        for i in range(len(matrix)):
            for j in range(len(matrix[0])):
                if matrix[i][j] == "1":
                    r = min(a[i-1][j], a[i-1][j-1], a[i][j-1]) + 1
                    a[i][j] = r
                    if r > m:
                        m = r
                else:
                    a[i][j] = 0
        for l in a:
            print(l)
        return m*m