Number Of Rectangles That Can Form The Largest Square LeetCode solution in Python

1
# Runtime: 239 ms (Top 76.52%) | Memory: 14.6 MB (Top 25.99%)
2

3

4
class Solution:
5
def countGoodRectangles(self, rectangles: List[List[int]]) -> int:
6

7
# Runtime: 184 ms, faster than 65.71% of Python3 online submissions
8
# Memory Usage: 14.9 MB, less than 39.90% of Python3 online submissions
9

10
res = []
11

12
minSide = 0
13
maxLen = 0
14

15
for l, w in rectangles:
16

17
minSide = min(l, w) # Gets minSide of each rectangle
18

19
if minSide > maxLen: # Checks if rectangle holds new maxLen
20
maxLen = minSide # Tracks the current maxLen
21

22
res.append(minSide) # Holds each rectangles minSIde
23

24
return res.count(
25
maxLen
26
) # Returns the count of rectangles whos minSide is equal to maxLen

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0