221. Maximal Square
来源:互联网 发布:淘宝商场正品代购 编辑:程序博客网 时间:2024/06/06 01:36
题意: 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 01 0 1 1 11 1 1 1 11 0 0 1 0
Return 4.
思路:还是典型的DP问题,递推式为
class Solution {public: int maximalSquare(vector<vector<char>>& matrix) { int res = 0; for (int i=0;i<matrix.size();i++){ for(int j=0;j<matrix[0].size();j++){ int a = (i&&j)?matrix[i-1][j-1]:0; int b = i?matrix[i-1][j]:0; int c = j?matrix[i][j-1]:0; matrix[i][j] = matrix[i][j]=='1'?(min(a,min(b,c))+1):0; res = max(res,matrix[i][j]*matrix[i][j]); } } return res; }};
0 0
- 221.Maximal Square
- [leetcode] 221.Maximal Square
- 【leetcode】221. Maximal Square
- [LeetCode]221. Maximal Square
- leetcode 221. Maximal Square
- 221. Maximal Square LeetCode
- 221. Maximal Square
- 221. Maximal Square
- LeetCode 221. Maximal Square
- 221. Maximal Square
- LeetCode *** 221. Maximal Square
- 221. Maximal Square
- LeetCode-221.Maximal Square
- leetcode.221. Maximal Square
- 221. Maximal Square
- Leetcode 221. Maximal Square
- 221. Maximal Square
- 221. Maximal Square
- C++ Primer_4th学习笔记(3)- 引用
- 深入浅出FPGA-3-verilog HDL
- eclipse搭建android开发环境
- 利用用户行为数据(1)——userCF
- 前端最全API
- 221. Maximal Square
- Git入门及上传项目到github中
- TypeError: unhashable type: 'list'
- 如何阅读文献(一)
- Visual Studio 2013 搭建OpenGL平台
- 欢迎使用CSDN-markdown编辑器
- Android源码(window下如何获取)
- 牛腩(11)-新闻发布系统大总结
- 【Unity3d游戏开发】浅谈Unity中的GC以及优化