程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

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)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved