Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func maximalSquare(_ matrix: [[Character]]) -> Int {
- guard matrix.count > 0 && matrix[0].count > 0 else { return 0}
- let n = matrix.count
- let m = matrix[0].count
- var dp = [[Int]](repeating: [Int](repeating: 0, count: m), count: n)
- var count = 0
- for i in 0 ..< n{
- for j in 0 ..< m {
- if matrix[i][j] == "1"{
- dp[i][j] = 1
- if i > 0 && j > 0 {
- dp[i][j] = min(dp[i - 1][j] , dp[i - 1][j - 1], dp[i][j - 1]) + 1
- }
- count = max(count , dp[i][j] )
- }
- }
- }
- return count * count
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement