Leetcode 算法设计 第十三周
来源:互联网 发布:淘宝卖家星级怎么升级 编辑:程序博客网 时间:2024/04/20 08:30
221. Maximal Square
Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.
For example, given the following matrix:
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0
Return 4.
题目大意
在给定的数组中找到元素都为1的最大矩阵
我的解答
class Solution {public: int maximalSquare(vector<vector<char>>& matrix) { if(matrix.size() == 0)return 0; int maxsqu = 0; int x = matrix.size(); int y = matrix[0].size(); vector<vector<int>> dp(x+1,vector<int>(y+1,0)); for(int i = 1; i <= x; i++){ for(int j = 1; j <= y; j++){ if(matrix[i-1][j-1] == '1'){ dp[i][j] = min(min(dp[i-1][j-1],dp[i-1][j]),dp[i][j-1])+1; maxsqu = max(maxsqu,dp[i][j]); } } } return maxsqu * maxsqu; }};
阅读全文
0 0
- Leetcode 算法设计 第十三周
- Leetcode 算法设计 第十三周
- Leetcode 算法设计 第十三周
- leetcode 第十三周算法报告
- 第十三周LeetCode算法题
- Leetcode 算法习题 第十三周
- Leetcode 算法习题 第十三周
- 算法设计与应用基础:第十三周
- 算法分析与设计第十三周
- 算法分析与设计丨第十三周丨LeetCode(17)——Coin Change(Medium)
- leetcode-python 第十三周
- leetcode-第十三周
- 第十三周leetcode题
- 第十三周LeetCode
- 第十三周LeetCode
- 第十三周LeetCode
- 第十三周LeetCode
- LeetCode题解 第十三周
- dedecms获取顶级栏目名称、二级栏目名称实现方法
- $page = $_GET['page'] 和 empty($page) 返回 true
- Spring MVC注解@Valid、@JsonSerialize、@JsonView等
- 最详细的maven教程
- python 路径处理
- Leetcode 算法设计 第十三周
- java 泛型 extends 和 super快速记忆。
- 6XML Schema
- 解决Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
- Hibernate与 MyBatis的比较
- java正则表达式
- USB四种传输模式
- 输出斐波那契(Fibonacci)数列的前二十项
- xcode9 修改icon步骤