forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0085.py
More file actions
27 lines (21 loc) · 714 Bytes
/
0085.py
File metadata and controls
27 lines (21 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution:
def maximalRectangle(self, matrix):
"""
:type matrix: List[List[str]]
:rtype: int
"""
if not matrix:
return 0
nums, area = [int(''.join(row), base=2) for row in matrix], 0
for i in range(len(nums)):
num = -1
for j in range(i, len(nums)):
num &= nums[j]
if not num:
break
n, l = num, 0
while n:
l += 1
n &= n << 1
area = max(area, l * (j - i + 1))
return area