leetcode764 Largest Plus Sign
思路:
首先使用dp计算出在每个位置(i, j)上下左右最多有多少个连续的1,得到up[i][j], down[i][j], left[i][j], right[i][j]。然后计算这四个值中的最小值,所有最小值中的最大值就是答案。
实现:
class Solution
{
public:
int orderOfLargestPlusSign(int N, vector<vector<int>>& mines)
{
vector<vector<int>> left(N, vector<int>(N, )), right(N, vector<int>(N, ));
vector<vector<int>> up(N, vector<int>(N, )), down(N, vector<int>(N, ));
vector<vector<int>> a(N, vector<int>(N, ));
for (int i = ; i < mines.size(); i++)
a[mines[i][]][mines[i][]] = ;
for (int i = ; i < N; i++)
{
left[i][] = (a[i][] == ? : );
right[i][N - ] = (a[i][N - ] == ? : );
for (int j = ; j < N; j++)
{
left[i][j] = a[i][j] == ? : left[i][j - ] + ;
right[i][N - - j] = a[i][N - - j] == ? : right[i][N - j] + ;
}
}
for (int j = ; j < N; j++)
{
up[][j] = (a[][j] == ? : );
down[N - ][j] = (a[N - ][j] == ? : );
for (int i = ; i < N; i++)
{
up[i][j] = a[i][j] == ? : up[i - ][j] + ;
down[N - - i][j] = a[N - - i][j] == ? : down[N - i][j] + ;
}
}
int maxn = ;
for (int i = ; i < N; i++)
{
for (int j = ; j < N; j++)
{
int tmp = min(min(min(up[i][j], down[i][j]), left[i][j]), right[i][j]);
maxn = max(maxn, tmp);
}
}
return maxn;
}
};
leetcode764 Largest Plus Sign的更多相关文章
- [Swift]LeetCode764. 最大加号标志 | Largest Plus Sign
In a 2D grid from (0, 0) to (N-1, N-1), every cell contains a 1, except those cells in the given lis ...
- [LeetCode] Largest Plus Sign 最大的加型符号
In a 2D grid from (0, 0) to (N-1, N-1), every cell contains a 1, except those cells in the given lis ...
- 764. Largest Plus Sign最大的dfs十字架
[抄题]: 求挖掉一些区域后,能允许出现的最大十字架 In a 2D grid from (0, 0) to (N-1, N-1), every cell contains a 1, except t ...
- 【leetcode】Largest Plus Sign
题目如下: In a 2D grid from (0, 0) to (N-1, N-1), every cell contains a 1, except those cells in the giv ...
- 【LeetCode】764. Largest Plus Sign 解题报告(Python)
[LeetCode]764. Largest Plus Sign 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn ...
- leetcode 764.Largest Plus Sign
根据题意的话就是在非0的地方开始寻找上下左右分别能够走到的最大步长的. 那么使用暴力的方法竟然leetcode还是给过了. class Solution { public: int orderOfLa ...
- 764. Largest Plus Sign
题目大意: 就是一个由1和0组成的正方形矩阵,求里面最大的加号的大小,这个大小就是长度. 什么鬼啊,本来想自己想的,结果看了半天没看懂具体什么意思,然后查了下题解,希望有人说一下意思,结果一上来就是思 ...
- [LeetCode] Minimum Window Subsequence 最小窗口序列
Given strings S and T, find the minimum (contiguous) substring W of S, so that T is a subsequence of ...
- Swift LeetCode 目录 | Catalog
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift 说明:题目中含有$符号则为付费题目. 如 ...
随机推荐
- VS code - code Snippet
For anyone working on the UI and using VS Code, you can create a user Snippet and keyboard shortcut ...
- 3 微信开发本地代理环境的搭建--实现将内网ip映射到外网
微信公众号的开发,要搭建网站,并且随时都有可能修改网站内容进行调试,这就需要临时外网能返回本地开发环境搭建的项目进行测试,即内网映射到公网,但是好多开发者没有自己的域名和服务器,这里我们先来搭建一个本 ...
- 算法4-10:BST平衡二叉树的删除操作
偷懒方法 public void delete(Key key) { insert(key, null); } 这样的方法就是将key相应的值覆盖成null.当读取该键值的时候将会返回null. 这是 ...
- USING REFLECTION
In this section, you take a closer look at the System.Type class, which enables you to access inform ...
- mysql13---索引使用注意
.4唯一索引 ①当表的某列被指定为unique约束时,这列就是一个唯一索引 ) unique); 这时, name 列就是一个唯一索引. unique字段可以为NULL,并可以有多NULL(,null ...
- mongodb10---分片
分片:数据非常大,把不同段的数据拆了,1-1000000放在节点1,1000000-2000000放在节点2,200000-300000放在节点上.把不同的数据放在不同的服务器叫shard分片. 请求 ...
- HDU1257 最少拦截系统 —— 贪心
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Othe ...
- 比特币钱包的bitcoin-cli 命令全集
A.一般性的命令 help ( "command" ) stopgetinfopinggetnettotalsgetnetworkinfogetpeerinfogetconnect ...
- mac系统下mysql5.7.13数据库编码查看和设置
1.查看编码命令: mysql> show variables like '%character%'; +--------------------------+----------------- ...
- 并不对劲的splay
splay和不加任何旋转一定会被卡的二叉搜索树的唯一区别就是每次操作把当前节点旋转到根. 旋转有各种zig.zag的组合方式,感觉很麻烦,并不对劲的人并不想讲. 其实可以找出一些共性将它们合并.设ls ...