Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a2ee4f3

Browse files
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)

AltStyle によって変換されたページ (->オリジナル) /