题目:
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:
[ "0010", "0110", "0100" ]and

这篇博客主要介绍了LeetCode中的问题302,如何找到最小的矩形来包围图像中的所有黑色像素。作者提出了两种解决方案:1) 使用深度优先搜索(DFS),从给定的黑色像素位置开始搜索,时间复杂度为O(m*n),m和n是图像的高度和宽度。2) 使用二分查找法,时间复杂度更优,为O(mlogn + nlogm)。文章还给出了DFS和二分查找的代码实现。
最低0.47元/天 解锁文章
335

被折叠的 条评论
为什么被折叠?



