Skip to content

Commit e43934e

Browse files
authored
Create number-of-rectangles-that-can-form-the-largest-square.py
1 parent 79c93d0 commit e43934e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def countGoodRectangles(self, rectangles):
6+
"""
7+
:type rectangles: List[List[int]]
8+
:rtype: int
9+
"""
10+
result = mx = 0
11+
for l, w in rectangles:
12+
side = min(l, w)
13+
if side > mx:
14+
result, mx = 1, side
15+
elif side == mx:
16+
result += 1
17+
return result

0 commit comments

Comments
 (0)