Based on my **shorter Ruby version**. Still using ruichang's idea to use binary search.

```
def minArea(self, image, x, y):
def first(lo, hi, check):
while lo < hi:
mid = (lo + hi) / 2
if check(mid):
hi = mid
else:
lo = mid + 1
return lo
top = first(0, x, lambda x: '1' in image[x])
bottom = first(x, len(image), lambda x: '1' not in image[x])
left = first(0, y, lambda y: any(row[y] == '1' for row in image))
right = first(y, len(image[0]), lambda y: all(row[y] == '0' for row in image))
return (bottom - top) * (right - left)
```

The `first`

function could also use the `bisect`

module, for example:

```
def first(lo, hi, check):
self.__getitem__ = check
return bisect.bisect(self, False, lo, hi)
def first(lo, hi, check):
class Checker: __getitem__ = staticmethod(check)
return bisect.bisect(Checker(), False, lo, hi)
```

The first one is a bit dirtier, and requires `class Solution:`

instead of `class Solution(object):`

.