Leetcode[1725] python3 implementation of the number of rectangles that can form the largest square
編輯:Python
# Give you an array rectangles , among rectangles[i] = [li, wi] It means the first one i The length of a rectangle is li 、 Width is wi .
#
# If there is k At the same time satisfy k <= li and k <= wi , You can put the second i A rectangle is cut into two sides k The square of . for example , rectangular [4,6] It can be cut into sides up to
# 4 The square of .
#
# set up maxLen For you can select from a rectangular array rectangles It's a cut The largest square The length of .
#
# Please count how many rectangles can be cut out, and the side length is maxLen The square of , And returns the rectangle number .
#
#
#
# Example 1:
#
#
# Input :rectangles = [[5,8],[3,9],[5,12],[16,5]]
# Output :3
# explain : The maximum square lengths that can be cut from each rectangle are [5,3,5,5] .
# The side length of the largest square is 5 , Can be 3 Cut a rectangle to get .
#
#
# Example 2:
#
#
# Input :rectangles = [[2,3],[3,7],[4,3],[3,7]]
# Output :3
#
#
#
#
# Tips :
#
#
# 1 <= rectangles.length <= 1000
# rectangles[i].length == 2
# 1 <= li, wi <= 10⁹
# li != wi
#
# Related Topics Array 17 0
# leetcode submit region begin(Prohibit modification and deletion)
class Solution:
def countGoodRectangles(self, rectangles: List[List[int]]) -> int:
max_len = 0
ret = 0
for rec in rectangles:
cur = min(rec)
if cur > max_len:
max_len = cur
ret = 1
elif cur == max_len:
ret += 1
return ret
# leetcode submit region end(Prohibit modification and deletion)