Skip to content

Commit 72addde

Browse files
committed
Resolved 'Number Of Rectangles That Can Form The Largest Square' LeetCode problem with an optimized solution
1 parent 708876c commit 72addde

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Number Of Rectangles That Can Form The Largest Square
2+
3+
class Solution(object):
4+
def countGoodRectangles(self, rectangles):
5+
max_side_length = 0
6+
count = 0
7+
8+
for rectangle in rectangles:
9+
side_length = min(rectangle)
10+
max_side_length = max(max_side_length, side_length)
11+
12+
for rectangle in rectangles:
13+
if min(rectangle) >= max_side_length:
14+
count += 1
15+
16+
return count
17+
18+
solution = Solution()
19+
print(solution.countGoodRectangles([[5,8],[3,9],[5,12],[16,5]]))

0 commit comments

Comments
 (0)