思路:

首先使用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的更多相关文章

  1. [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 ...

  2. [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 ...

  3. 764. Largest Plus Sign最大的dfs十字架

    [抄题]: 求挖掉一些区域后,能允许出现的最大十字架 In a 2D grid from (0, 0) to (N-1, N-1), every cell contains a 1, except t ...

  4. 【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 ...

  5. 【LeetCode】764. Largest Plus Sign 解题报告(Python)

    [LeetCode]764. Largest Plus Sign 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn ...

  6. leetcode 764.Largest Plus Sign

    根据题意的话就是在非0的地方开始寻找上下左右分别能够走到的最大步长的. 那么使用暴力的方法竟然leetcode还是给过了. class Solution { public: int orderOfLa ...

  7. 764. Largest Plus Sign

    题目大意: 就是一个由1和0组成的正方形矩阵,求里面最大的加号的大小,这个大小就是长度. 什么鬼啊,本来想自己想的,结果看了半天没看懂具体什么意思,然后查了下题解,希望有人说一下意思,结果一上来就是思 ...

  8. [LeetCode] Minimum Window Subsequence 最小窗口序列

    Given strings S and T, find the minimum (contiguous) substring W of S, so that T is a subsequence of ...

  9. Swift LeetCode 目录 | Catalog

    请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift    说明:题目中含有$符号则为付费题目. 如 ...

随机推荐

  1. 初探swift语言的学习笔记十一(performSelector)

    作者:fengsh998 原文地址:http://blog.csdn.net/fengsh998/article/details/35842441 转载请注明出处 假设认为文章对你有所帮助,请通过留言 ...

  2. 在webkit中如何避免触发layout(重排)

    很多web开发者都已经意识到,在脚本执行中,DOM操作的用时可能比js本身执行时间要长很多,其中潜在的消耗基本上是由于触发了layout(即重排reflow:由DOM树构建为Render渲染树的过程) ...

  3. 2016/3/30 租房子 ①建立租房子的增、删、改php页面 ②多条件查询 ③全选时 各部分全选中 任意checkbox不选中 全选checkbox不选中

    字符串的另一种写法:<<<AAAA; 后两个AA回车要求顶格  不然报错 例子: <!DOCTYPE html> <html lang="en" ...

  4. 自己写好的pdo数据库抽象层 mysql为例

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/qq1355541448/article/details/31787719 class pdo_dat ...

  5. YTU 2904: B--Faultfinding

    2904: B--Faultfinding 时间限制: 1 Sec  内存限制: 128 MB 提交: 64  解决: 33 题目描述 Do you remember the game in whic ...

  6. cassandra删除所有数据,重置为初始状态——删除<data dir>/data/* <data dir>/commitlog/* <data dir>/saved_caches/* 重启cassandra即可

    Are you looking for a method other than drop keyspace? Okay based on your clarification... I would s ...

  7. bash编程 将一个目录里所有文件存为一个array 并分割为三等分——利用bash array切片

    files=(a b c d e f g h i j k l m n o p)cnt="${#files[@]}"let cnt1="($cnt+2)/3"le ...

  8. 最好的6个Go语言Web框架

    原文:Top 6 web frameworks for Go as of 2017 作者:Edward Marinescu 译者:roy 译者注:本文介绍截至目前(2017年)最好的6个Go语言Web ...

  9. memcached value最大限制只能是1M吗

    关于memcached的value最大是1M的限制很多人都知道,但是如果你以为我还要说这个事情,那你就错了. 之前的老版本确实是只能是1M,但是根据git记录,其实2009年以后的版本这个value最 ...

  10. Linux Gcc编译错误(转载)

    转自:http://www.linuxidc.com/Linux/2012-01/52153.htm Linux系统下的c编程与Windows有所不同,如果你在用gcc编译代码的时候提示‘for’ l ...