Seawolf 发表于 2020-9-25 10:46:04

Leetcode 221. Maximal Square

Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.

Example:

Input:

1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0

Output: 4

class Solution:
    def maximalSquare(self, matrix: List]) -> int:
      if matrix == None or len(matrix) == 0 or len(matrix) == 0:
            return 0
      size = [) + 1)] for _ in range(len(matrix) + 1)]
      result = 0
      for i in range(1, len(matrix) + 1):
            for j in range(1, len(matrix) + 1):
                if matrix == '1':
                  size = min(size, size, size) + 1
                  result = max(result, size)
      return result * result
页: [1]
查看完整版本: Leetcode 221. Maximal Square