1 Star 0 Fork 0

wangzai / 力扣算法面试题

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
221. Maximal Square.cpp 758 Bytes
一键复制 编辑 原始数据 按行查看 历史
wangzai 提交于 2021-11-11 15:36 . 增加了221. 最大正方形
//
// Created by 旺崽 on 2021/11/11.
//
#include "bits/stdc++.h"
using namespace std;
class Solution {
public:
int maximalSquare(vector<vector<char>> &matrix) {
int r = matrix.size(), c = matrix[0].size(), ans = 0;
vector<vector<int>> dp(r, vector<int>(c, 0));
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (matrix[i][j] == '1') {
if (i == 0 || j == 0) dp[i][j] = 1;
else {
dp[i][j] = min({dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]}) + 1;
}
ans = max(ans, dp[i][j]);
}
}
}
return ans * ans;
}
};
int main() {
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qianlinyi/algorithmicQuestions.git
git@gitee.com:qianlinyi/algorithmicQuestions.git
qianlinyi
algorithmicQuestions
力扣算法面试题
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891