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. electron api sendInputEvent 源码

    electron-master\electron-master\shell\browser\api\atom_api_web_contents.cc // Copyright (c) 2014 Git ...

  2. bootstap 表格自动换行 截取超长数据

    <table class="table" style="TABLE-LAYOUT:fixed;WORD-WRAP:break_word">

  3. JNetPcap安装及使用

    啥是JNetPcap? JNetPcap是由Sly Technologies开发的开源DPI(Deep Packet Inspection)SDK. Java平台底层不支持底层网络操作,需要通过JNI ...

  4. 内核模式构造-Mutex构造(RecursiveAutoResetEvent)

    internal sealed class RecursiveAutoResetEvent : IDisposable { private AutoResetEvent m_lock = new Au ...

  5. 第11章 Spring Boot使用Actuator

    在生产环境中,需要实时或定期监控服务的可用性,spring-Boot的Actuator 功能提供了很多监控所需的接口. Actuator是Spring Boot提供的对应用系统的自省和监控的集成功能, ...

  6. 【input】标签去除默认样式

    input{-webkit-appearance: none; -moz-appearance: none; -o-appearance: none; appearance: none;}

  7. gitlab qq邮件配置

    https://blog.csdn.net/u010856284/article/details/83650364 gitlab 11.4以后的添加stmp根据官网出现了配置,导致不能测试通过,以下是 ...

  8. Quartus 18 新手使用教程

    最近需要做个小作品,用到了Quartus 18,本人采用vhdl语言进行的开发,过程如下. 1.点击新建一个工程 ​ 2.选择工程保存的路径,填写工程名称 ​ 3.选择工程类型为空的工程 ​ 4.不添 ...

  9. shell编程初探

    #! /bin/sh #这是神圣丁的第一个shell脚本 name="陈培昌" echo "我就喜欢\"$name\"" echo '我就喜 ...

  10. MySQL的btree索引和hash索引区别

     在使用MySQL索引的时候, 选择b-tree还是hash hash索引仅仅能满足"=","IN"和"<=>"查询,不能使用范 ...