Skip to content

Commit ec997f3

Browse files
authored
Create maximalSquare.py
1 parent 1c9bb01 commit ec997f3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Kangli/DP/maximalSquare.py

+13
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)