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. jquery 取指定class下的input checkbox选中的值

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. QTP(11)

    练习:录制Flight登录-打开1-10之间随机编号的订单-退出,打开完订单后,退出前,使用msgbox输出“顾客x预定了y从z到w的c类型的k张票!”说明:x是顾客姓名.y是日期.z是FlyFrom ...

  3. okhttp同步请求流程和源码分析

    在上一次[http://www.cnblogs.com/webor2006/p/8022808.html]中已经对okhttp的同步与异步请求的基本使用有了一了初步了解,这次来从源码的角度来分析一下同 ...

  4. Linux之yum软件管理

    YUM yum = Yellow dog Updater, Modified主要功能是更方便的添加/删除/更新RPM包.它能自动解决包的倚赖性问题. 它能便于管理大量系统的更新问题 yum特点 *可以 ...

  5. IntelliJ IDEA导包快捷键

    IntelliJ IDEA导包快捷键 Alt+Enter

  6. JSP+Servlet+DAO+Javabean模式小记-20171029

    1.Servlet的doPost方法使用request.getParameter()接收网页传送的form表单数据时,必须使用name属性,而不能使用id. 2.这是最简单的MVC模式,其中M(mod ...

  7. java面试题(目录版)

    在https://www.cnblogs.com/marsitman/p/9539369.html  根据自己以往的面试经验,在该基础上做了补充和删减,均链接到相应的地址(链接失效请留言评论). 一. ...

  8. Java思维题

    1.求取字符串中出现的第一个非重复字符.   比如: "hello" 中的 h, "hello, how r you?" 中的 e 2.使用26字符母实现加密 ...

  9. vue3.0以上关于打包后出现空白页和路由不起作用

    1.解决页面空白,找不到资源 在项目根目录中的vue.config.js中publicPath: '/'修改为publicPath: './',如果没有这个文件,新建一个,基础代码为: module. ...

  10. (转发)Android 源码获取-----在Windows环境下通过Git得到Android源代码

    在学习Android的过程中,深入其源代码研究对我们来说是非常重要的,这里将介绍如何通过在Windows环境下使用Git来得到我们的Android源代码. 1.首先确保你电脑上安装了Git,这个通过  ...