Created
December 5, 2018 19:21
-
-
Save farsialgorithm/42606e5e7c13475138661551643d6bf5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def maximalSquare(matrix): | |
| if matrix is None or len(matrix)==0: | |
| return 0 | |
| max_sq = 0 | |
| height, width = len(matrix), len(matrix[0]) | |
| dp = [[0 for i in range(width+1)] for j in range(height+1)] | |
| for i in range(1, height+1): | |
| for j in range(1, width+1): | |
| if matrix[i-1][j-1] == "1": | |
| dp[i][j] = min([dp[i-1][j], dp[i][j-1], dp[i-1][j-1]]) +1 | |
| max_sq = max(max_sq, dp[i][j]) | |
| return max_sq**2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment