leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | 336710072102d54d076b0b520d4268bff37dc708 |
parent | 0778f15ed04bd09dc551a19993bde58d81d37a34 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Sat, 13 Apr 2024 19:21:21 +0200 |
Daily Problem
Diffstat:A | Problems/0085.cpp | | | ++++++++++++++++++++++++++ |
M | README.md | | | + |
2 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/Problems/0085.cpp b/Problems/0085.cpp
@@ -0,0 +1,26 @@
class Solution {
public:
int maximalRectangle(const vector<vector<char>> &matrix) const {
const int n = size(matrix), m = size(matrix[0]);
static int dp[202][202] = {0};
int res = 0;
for (int i = n - 1; i >= 0; i--) {
dp[i][m] = 0;
for (int j = m - 1, acc = 0; j >= 0; j--) {
dp[i][j] = matrix[i][j] == '1' ? dp[i][j + 1] + 1 : 0;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
for (int l = i, len = m; l < n && matrix[l][j] == '1'; l++) {
len = min(len, dp[l][j]);
res = max(res, (l - i + 1) * len);
}
}
}
return res;
}
};
diff --git a/README.md b/README.md
@@ -107,6 +107,7 @@ for solving problems.
| 0082 | Medium | [Remove Duplicates from Sorted List II](Problems/0082.cpp) |
| 0083 | Easy | [Remove Duplicates from Sorted List](Problems/0083.cpp) |
| 0084 | Hard | [Largest Rectangle in Histogram](Problems/0084.cpp) |
| 0085 | Hard | [Maximal Rectangle](Problems/0085.cpp) |
| 0086 | Medium | [Partition List](Problems/0086.cpp) |
| 0087 | Hard | [Scramble String](Problems/0087.cpp) |
| 0088 | Easy | [Merge Sorted Array](Problems/0088.cpp) |