File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -55,9 +55,31 @@ dp[i - 1][j - 1]我们直接拿到,关键是`往上和往左进行延伸`, 最
55
55
56
56
## 代码
57
57
58
- ``` js
58
+ 代码支持:Python,JavaScript:
59
+
60
+ Python Code:
61
+
62
+ ``` python
63
+ class Solution :
64
+ def maximalSquare (self , matrix : List[List[str ]]) -> int :
65
+ res = 0
66
+ m = len (matrix)
67
+ if m == 0 :
68
+ return 0
69
+ n = len (matrix[0 ])
70
+ dp = [[0 ] * (n + 1 ) for _ in range (m + 1 )]
71
+
72
+ for i in range (1 , m + 1 ):
73
+ for j in range (1 , n + 1 ):
74
+ dp[i][j] = min (dp[i - 1 ][j], dp[i][j - 1 ], dp[i - 1 ][j - 1 ]) + 1 if matrix[i - 1 ][j - 1 ] == " 1" else 0
75
+ res = max (res, dp[i][j])
76
+ return res ** 2
77
+ ```
59
78
60
79
80
+ JavaScript Code:
81
+
82
+ ``` js
61
83
62
84
/*
63
85
* @lc app=leetcode id=221 lang=javascript
@@ -98,7 +120,8 @@ var maximalSquare = function(matrix) {
98
120
};
99
121
```
100
122
123
+
101
124
*** 复杂度分析***
102
- - 时间复杂度:$O(M * N)$,其中M为行数,N为列数。
103
- - 空间复杂度:$O(N)$,其中N为列数。
104
125
126
+ - 时间复杂度:$O(M * N)$,其中M为行数,N为列数。
127
+ - 空间复杂度:$O(M * N)$,其中M为行数,N为列数。
You can’t perform that action at this time.
0 commit comments