LC 302. Smallest Rectangle Enclosing Black Pixels【lock, hard】
An image is represented by a binary matrix with 0
as a white pixel and 1
as a black pixel. The black pixels are connected, i.e., there is only one black region. Pixels are connected horizontally and vertically. Given the location (x, y)
of one of the black pixels, return the area of the smallest (axis-aligned) rectangle that encloses all black pixels.
Example:
Input:
[
"0010",
"0110",
"0100"
]
andx = 0,
y = 2
Output: 6 简单题,记录DFS到达的最大上下左右值。
class Solution {
private:
int arr[][];
public:
int minArea(vector<vector<char>>& image, int x, int y) {
arr[][] = ;
arr[][] = ;
arr[][] = -;
arr[][] = ;
arr[][] = ;
arr[][] = ;
arr[][] = ;
arr[][] = -;
vector<int> ret;
//ret.push_back();
ret.push_back(INT_MAX);
ret.push_back(INT_MIN);
ret.push_back(INT_MAX);
ret.push_back(INT_MIN);
helper(image, x, y, ret);
//cout << ret[0] << ret[1] << ret[2] << ret[3] << endl;
return (ret[] - ret[] + ) * (ret[] - ret[] + );
}
void helper(vector<vector<char>>& image, int x, int y, vector<int>& ret){
if(image[x][y] == '') return;
image[x][y] = '';
//if(y == 0) cout << x << endl;
ret[] = min(x, ret[]);
ret[] = max(x, ret[]);
ret[] = min(y, ret[]);
ret[] = max(y, ret[]);
for(int i=; i<; i++){
if(x + arr[i][] < image.size() && x + arr[i][] >= && y + arr[i][] < image[].size() && y + arr[i][] >= ){
helper(image, x+arr[i][], y+arr[i][], ret);
}
}
}
};
LC 302. Smallest Rectangle Enclosing Black Pixels【lock, hard】的更多相关文章
- 【leetcode】302.Smallest Rectangle Enclosing Black Pixels
原题 An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The bl ...
- 302. Smallest Rectangle Enclosing Black Pixels
题目: An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The b ...
- [LeetCode] Smallest Rectangle Enclosing Black Pixels 包含黑像素的最小矩阵
An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black ...
- Smallest Rectangle Enclosing Black Pixels
An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black ...
- LeetCode Smallest Rectangle Enclosing Black Pixels
原题链接在这里:https://leetcode.com/problems/smallest-rectangle-enclosing-black-pixels/ 题目: An image is rep ...
- [Locked] Smallest Rectangle Enclosing Black Pixels
An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black ...
- Smallest Rectangle Enclosing Black Pixels 解答
Question An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. ...
- [Swift]LeetCode302. 包含黑色像素的最小矩形 $ Smallest Rectangle Enclosing Black Pixels
An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black ...
- LC 871. Minimum Number of Refueling Stops 【lock, hard】
A car travels from a starting position to a destination which is target miles east of the starting p ...
随机推荐
- Django框架——forms.ModelForm使用
使用模型创建表单 django提供了这种简便的方式,使用方法如下: 1.在项目的一个app目录中,创建forms.py文件 2.导入模块: from django import forms from ...
- deep_learning_neural network梯度下降
神经网络优化算法:梯度下降法.Momentum.RMSprop和Adam 最近回顾神经网络的知识,简单做一些整理,归档一下神经网络优化算法的知识.关于神经网络的优化,吴恩达的深度学习课程讲解得非常通俗 ...
- Linux:fdisk
fdisk [-l] 装置名称 选项与参数: -l:输入后面接的装置所有的partition内容.若仅有fdisk -l时,则系统将会把整个系统内能够搜寻到的装置的partition均列出来 fdis ...
- CentOS7.x卸载与安装MySQL5.7的操作过程以及编码格式的修改
一.MySQL5.7的卸载 1.1yum方式查看yum是否安装过mysql cd yum list installed mysql* 如或显示了列表,说明系统中有MySQL 如上显示,我已经安装了my ...
- Java io 理解
任何程序都有io部分,io是对程序来说数据流的输入和输出.这里说的流,是指有字节组成的列,不断输入程序,或者从程序中输出,我们形象称为流.Java的io流有两种,一种叫字节流,最原始的:一种叫字符流. ...
- php生成word并下载
1.前端代码: index.html <!DOCTYPE html> <html> <head> <title>PHP生成Word文档</ti ...
- vue插件——滚动监听 vue-scrollwatch
造轮子的目的: 做项目的时候需要一个滚动监听的功能,html结构已经都写好了,不想使用vue组件的方式来写,因为不想改造html结构,于是花了几个小时做了一个简单的,使用vue指令方式来做的,项目上够 ...
- 一例swoole_process运行swoole_http_server
swoole_process swoole_process('执行的文件路径','文件所需的参数');//利用swoole-process执行一个外部脚本 swoole_process__constr ...
- php类相关知识----类常量,静态变量
类常量 <?php class myuser { ;//定义的常量不带$符号,常量之前没有访问修饰符,常量之前没有修饰符号 public function monolog() { echo &q ...
- docker下安装运行mysql的过程以mysql5.7为例
一.查找mysql资源 docker search mysql 其实这步顶多是看看有哪些mysql资源,除非你自己commit过一个特定的版本,否则直接执行下一步 二.安装mysql docker p ...