class Solution:
    def maximalSquare(self, A):
        """
        :type matrix: List[List[str]]
        :rtype: int
        """
        ans = 0
        for i in range(len(A)):
            for j in range(len(A[i])):
                A[i][j] = int(A[i][j])
                if A[i][j] and i and j:
                    A[i][j] = min(A[i-1][j], A[i-1][j-1], A[i][j-1]) + 1
                if A[i][j] > ans:
                    ans = A[i][j]
        return ans ** 2