Skip to content

Commit 72e115d

Browse files
author
lucifer
committed
feat: 语言优化
1 parent 5a0d167 commit 72e115d

File tree

2 files changed

+6
-35
lines changed

2 files changed

+6
-35
lines changed

problems/84.largest-rectangle-in-histogram.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ https://leetcode-cn.com/problems/largest-rectangle-in-histogram/
1111
![](https://tva1.sinaimg.cn/large/007S8ZIlly1ghltx8sr4uj305805odfn.jpg)
1212

1313
以上是柱状图的示例,其中每个柱子的宽度为 1,给定的高度为  [2,1,5,6,2,3]
14-
14+

1515
![](https://tva1.sinaimg.cn/large/007S8ZIlly1ghltx9kgd2j305805oa9z.jpg)
1616

1717
图中阴影部分为所能勾勒出的最大矩形面积,其面积为  10  个单位。

problems/85.maximal-rectangle.md

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ https://leetcode-cn.com/problems/maximal-rectangle/
5757

5858
## 代码
5959

60-
代码支持:Python, CPP
60+
代码支持:Python
6161

6262
Python Code:
6363

@@ -88,42 +88,13 @@ class Solution:
8888

8989
```
9090

91-
CPP Code:
92-
93-
```cpp
94-
class Solution {
95-
public:
96-
int maximalRectangle(vector<vector<char>>& A) {
97-
if (A.empty() || A[0].empty()) return 0;
98-
int ans = 0, M = A.size(), N = A[0].size();
99-
vector<int> left(N, 0), right(N, N), height(N, 0);
100-
for (int i = 0; i < M; ++i) {
101-
int curLeft = 0, curRight = N;
102-
for (int j = 0; j < N; ++j) height[j] = A[i][j] == '1' ? height[j] + 1 : 0;
103-
for (int j = 0; j < N; ++j) {
104-
if (A[i][j] == '1') left[j] = max(left[j], curLeft);
105-
else {
106-
left[j] = 0;
107-
curLeft = j + 1;
108-
}
109-
}
110-
for (int j = N - 1; j >= 0; --j) {
111-
if (A[i][j] == '1') right[j] = min(right[j], curRight);
112-
else {
113-
right[j] = N;
114-
curRight = j;
115-
}
116-
}
117-
for (int j = 0; j < N; ++j) ans = max(ans, (right[j] - left[j]) * height[j]);
118-
}
119-
return ans;
120-
}
121-
};
122-
```
123-
12491
**复杂度分析**
12592

12693
- 时间复杂度:$O(M * N)$
12794
- 空间复杂度:$O(N)$
12895

12996
以上就是本文的全部内容了。大家对此有何看法,欢迎给我留言,我有时间都会一一查看回答。更多算法套路可以访问我的 LeetCode 题解仓库:https://github.com/azl397985856/leetcode 。 目前已经 38K star 啦。大家也可以关注我的公众号《力扣加加》带你啃下算法这块硬骨头。
97+
98+
```
99+
100+
```

0 commit comments

Comments
 (0)