Skip to content

Commit a233c66

Browse files
committed
update
1 parent 305960b commit a233c66

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

P102. 最大正方形.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
***在一个由 '0' 和 '1' 组成的二维矩阵内,找到只包含 '1' 的最大正方形,并返回其面积。***
2+
3+
![algo41](./images/algo41.jpg)
4+
5+
```
6+
class Solution:
7+
def maximalSquare(self, matrix: List[List[str]]) -> int:
8+
#dp(i, j) 是以 matrix(i - 1, j - 1) 为 右下角 的正方形的最大边长。
9+
m = len(matrix)
10+
n = len(matrix[0])
11+
12+
dp = [[0]*(n+1) for _ in range(m+1)]
13+
res = 0
14+
for i in range(1, m+1):
15+
for j in range(1, n+1):
16+
if matrix[i-1][j-1] == '1':
17+
dp[i][j] = min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1])+1
18+
res = max(res, dp[i][j]*dp[i][j])
19+
return res
20+
```

images/algo41.jpg

24.5 KB
Loading

0 commit comments

Comments
 (0)