Smallest Rectangle Enclosing Black Pixels

An image is represented by a binary matrix with0as a white pixel and1as 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

For example, given the following image:

[
  "0010",
  "0110",
  "0100"
]

and x =0, y =2, Return6.

Note

即找出黑色虚线虚线框

黑色虚线框是什么呢, 是上下左右四个位置:

左:第一个出现绿色的列 (0 to y)

右:最后一个出现绿色的列 (y to n - 1)

上:第一个绿的行 (0 to x)

下:最后一个绿的行 (x to m - 1)

二分法的判断条件是该或者是不是全部都是0

Code

Last updated