221. Maximal Square
来源:互联网 发布:atm机java代码 编辑:程序博客网 时间:2024/06/13 07:34
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.
class Solution { public int maximalSquare(char[][] matrix) { if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { return 0; } int m = matrix.length, n = matrix[0].length; int[][] f = new int[m + 1][n + 1]; int max = 0; for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (matrix[i - 1][j - 1] == '1') { f[i][j] = Math.min(f[i - 1][j - 1], Math.min(f[i][j - 1], f[i - 1][j])) + 1; max = Math.max(max, f[i][j]); } } } return max * max; }}
阅读全文
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
- dorado给日期控件格式化
- 数据结构实验之排序一:一趟快排
- RocketMQ原理解析-broker 1. broker的启动
- Apache2 httpd.conf 配置详解
- linux 用法小结
- 221. Maximal Square
- linux下配置jdk环境变量以及查看java版本
- 中国计算机学会CCF推荐国际学术会议和期刊目录-计算机体系结构/并行与分布计算/存储系统
- MySQL2
- 一个超级简单又实用的AES加密解密字符串示例
- PL1167
- SQL FUNCTION
- 安卓基础之点击buttonview变颜色
- android studio 3.0使用java8