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. linux网络协议栈--路由流程分析

    转:http://blog.csdn.net/hsly_support/article/details/8797976 来吧,路由 路由是网络的核心,是linux网络协议栈的核心,我们找个入口进去看看 ...

  2. sourceforge.net

    https://sourceforge.net/ SourceForge.net,又称SF.net,是开源软件开发者进行开发管理的集中式场所. SourceForge.net由VA Software提 ...

  3. LNMP安装与配置之CentOS7的安装。

    LNMP与LAMP是我们常见的两种网站服务器架构.LNMP代表的就是Linux系统下Nginx+MySQL+PHP/Python,LAMP代表的则是Linux系统下Apache+MySQL+PHP/P ...

  4. Linux用户组管理及用户权限4

    权限管理:    ls -l        rwxrwxrwx:            左三位:定义user(owner)的权限            中三位:定义group的权限           ...

  5. lib异步中断

    基于libusbx-1.0.18-rc1,libusbx现已重新merage到libusb.1. 初始化使用libusb_init初始化libusb,如果是单设备通信,ctx参数可以传NULL,表示使 ...

  6. 第八章 watch监听 83 名称案例-使用watch监听文本框数据的变化

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  7. bom操作,事件与jquery

    BOM操作中 window关键字 可以不写 DOM操作 学习如何查找节点 如何查找标签 选择器 事件 当符合某个条件下 自动触发的动作/响应 js绑定事件的方式 方式1 不推荐使用 <butto ...

  8. cmd_memo

    1. bind host or ip:port #指定域名 curl -H 'Host:www.tsuiz.com' http://10.14.54.131:8080/check.do #指定ip和端 ...

  9. Android Gradle 常用配置

    Gradle:multiDexEnabled之DEX 方法超过64K限制和gradle编译OOM问题解决DEX 方法超过64K限制 UNEXPECTED TOP-LEVEL EXCEPTION: co ...

  10. springcloud实践(三)之断路器:Hystrix

    服务雪崩效应 基础服务的故障导致级联故障,进而造成了整个分布式系统的不可用,这种现象被称为服务雪崩效应.服务雪崩效应描述的是一种因服务提供者的不可用导致服务消费者的不可用,并将不可用逐渐放大的过程. ...