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"
]
and x = 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】的更多相关文章

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

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

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

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

  5. LeetCode Smallest Rectangle Enclosing Black Pixels

    原题链接在这里:https://leetcode.com/problems/smallest-rectangle-enclosing-black-pixels/ 题目: An image is rep ...

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

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

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

  9. 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 ...

随机推荐

  1. C++typedef struct和struct的区别

    #include "pch.h" #include struct struct1 { int a; char b; char* c; }test1;//定义结构体变量 typede ...

  2. go语言时间函数

    以YY-mm-dd HH:MM:SS.9位 输出当前时间: func main() { fmt.Println(time.Now()) // 2019-11-15 16:26:12.4807588 + ...

  3. deep_learning_Function_list变量前面加星号,字典变量前面加两个星号

    列表前面加星号作用是将列表解开成两个独立的参数,传入函数, 字典前面加两个星号,是将字典解开成独立的元素作为形参. def add(a, b): return a+b data = [4,3] pri ...

  4. NTP时间同步服务和DNS服务

    NTP服务是搭建集群的第一步,是保持时间的同步性,保持一致 服务端 首先下载 yum install ntp –y 而后打开配置文件 /etc/ntp.conf 配置文件里有很多内容,但只要留三行就足 ...

  5. BZOJ 1006 完美消除序列&最大势算法&弦图

    K国是一个热衷三角形的国度,连人的交往也只喜欢三角原则.他们认为三角关系:即AB相互认识,BC相互认识,CA相互认识,是简洁高效的.为了巩固三角关系,K国禁止四边关系,五边关系等等的存在.所谓N边关系 ...

  6. Linux用户组账号文件——group和gshadow

     /etc/passwd文件中包含着每个用户的用户组ID(GID). /etc/group文件对用户组的许可权限的控制并不是必要的,这是因为Linux系统用来自于/etc/passwd文件的UID.G ...

  7. 部署jenkins+git

    Jenkins简介 Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能 安装并启动思路: 安装准备 ...

  8. Web Api(3)

    Web API中的路由. 路由机制会把一个请求的URL映射到一个Controller上面的Action.这一点很关键.也就说你发送一个Http请求,MVC框架会解析这个请求的URL,之后尝试把它去映射 ...

  9. JS 函数相关的声明调用

    // 函数声明方法一 function f (a, b) { return a + b; } // 函数调用 console.log(f(1, 4)); // 函数声明方法二 var num = fu ...

  10. ARDUINO UNO烧录BOOTLOADER

    批量烧录为了速度加快,使用USBASP工具,配合PROGISP软件进行烧录. 因为脱离了ARDUINO IDE,所以需要研究AVR单片机的熔丝位设置问题. 刷ATMEGA32U4芯片,需要这样设置: ...