Skip to content

Commit a2ee4f3

Browse files
authored
Create maximalSquare.py
1 parent 5a48232 commit a2ee4f3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Kangli/DP/maximalSquare.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution(object):
2+
def maximalSquare(self, matrix):
3+
if not matrix:
4+
return 0
5+
m , n = len(matrix),len(matrix[0])
6+
dp = [[0 if matrix[i][j]=='0' else 1 for j in xrange(n)]for i in xrange(m)]
7+
for i in range(1, len(matrix)):
8+
for j in range(1, len(matrix[0])):
9+
if matrix[i][j] == '1':
10+
dp[i][j] = 1 + int(min(dp[i-1][j-1], dp[i-1][j], dp[i][j-1]))
11+
maxEdge = max(max(row) for row in dp)
12+
return maxEdge**2
13+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy