当前位置:网站首页>力扣(LeetCode)221. 最大正方形(2022.08.09)
力扣(LeetCode)221. 最大正方形(2022.08.09)
2022-08-10 06:08:00 【ChaoYue_miku】
在一个由 ‘0’ 和 ‘1’ 组成的二维矩阵内,找到只包含 ‘1’ 的最大正方形,并返回其面积。
示例 1:
输入:matrix = [[“1”,“0”,“1”,“0”,“0”],[“1”,“0”,“1”,“1”,“1”],[“1”,“1”,“1”,“1”,“1”],[“1”,“0”,“0”,“1”,“0”]]
输出:4
示例 2:
输入:matrix = [[“0”,“1”],[“1”,“0”]]
输出:1
示例 3:
输入:matrix = [[“0”]]
输出:0
提示:
m == matrix.length
n == matrix[i].length
1 <= m, n <= 300
matrix[i][j] 为 ‘0’ 或 ‘1’
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/maximal-square
C++提交内容:
class Solution {
public:
int maximalSquare(vector<vector<char>>& matrix) {
if (matrix.size() == 0 || matrix[0].size() == 0) {
return 0;
}
int maxSide = 0;
int rows = matrix.size(), columns = matrix[0].size();
vector<vector<int>> dp(rows, vector<int>(columns));
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
if (matrix[i][j] == '1') {
if (i == 0 || j == 0) {
dp[i][j] = 1;
} else {
dp[i][j] = min(min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]) + 1;
}
maxSide = max(maxSide, dp[i][j]);
}
}
}
int maxSquare = maxSide * maxSide;
return maxSquare;
}
};
边栏推荐
- Parallax Mapping: More Realistic Texture Detail Representation (Part 1): Why Use Parallax Mapping
- 如何正确理解线程机制中常见的I/O模型,各自主要用来解决什么问题?
- ebp/栈帧/call stack
- 第11章 数据库的设计规范【2.索引及调优篇】【MySQL高级】
- Chapter 12 Other Database Tuning Strategies [2. Index and Tuning] [MySQL Advanced]
- MySQL事务隔离级别
- 数据库学习之数据类型
- BUUCTF Notes (web)
- Screen post-processing: Sobel operator to achieve edge detection
- Confluence可以连接数据库但是在下一步就报错了
猜你喜欢
A few lines of code can crash the system;
Chapter 12 Other Database Tuning Strategies [2. Index and Tuning] [MySQL Advanced]
Ingress Controller performance test(1)
语法基础(判断语句)
Tencent Cloud Song Xiang: Kubernetes cluster utilization improvement practice
[Network Security] Practice AWVS Range to reproduce CSRF vulnerability
高级测试:如何使用Flink对Strom任务的逻辑功能进行复现测试?
COLMAP+OpenMVS实现物体三维重建mesh模型
BUUCTF笔记(web)
761. Special Binary Sequences
随机推荐
什么是代理ip?市面上好用的代理软件有哪些
机器学习_LGB调参汇总(开箱即食)
如何在VMlogin中设置YiLu代理?
761. 特殊的二进制序列
2022 Henan Mengxin League Game (5): University of Information Engineering C - Throwing a Handkerchief
761. Special Binary Sequences
关于研究鼠标绘制平滑曲线的阶段总结
Everyone, the default configuration of oracle cdc occasionally takes 30 seconds to capture data. How to optimize this?
关于Qt高频率信号槽合并的误解和方案
Quickly grasp game resources in one hour and remote hot update
NetKeeper(创翼)开WIFI方法——2018.5
socket实现进程间通信
结构体初阶
2022河南萌新联赛第(五)场:信息工程大学 F - 分割草坪
各位大佬,oracle11g,cdc2.2,flink1.13.6,单表增量同步。在没新增数据的情
High quality WordPress download station 5 play theme template
强化学习_06_pytorch-DQN实践(CartPole-v0)
关于MongoDb查询Decimal128转BigDecimal问题
npm搭建私服,上传下载包
Please pay attention to me, thank you.