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 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.
For example, given the following image:
and x = 0, y = 2
there is only one black region. 只有一个黑区
So, no need to worry about 1s spread across the matrix.
Brute force: Traverse the entire array, if it encounters 1, update the rectangle.
Improvement, with a given black pixel (x, y) as the center, use the binary search to quickly find the upper, lower, left, and right critical points of the entire black area, and then directly calculate the area.