Post

leetcode(리트코드)-1725 Number Of Rectangles That Can Form The Largest Square(PYTHON)

leetcode 1725 - Number Of Rectangles That Can Form The Largest Square 문제입니다.

1. 문제

https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square/


2. Input , Output


3. 분류 및 난이도

Eazy 난이도 문제입니다.


4. 문제 해석


5. code

코드설명

  • 각 리스트의 요소는 사각형의 폭과 높이입니다.
  • 변을 잘라서 정사각형을 만들 때 가장 폭이 긴 정사각형의 갯수를 리턴하세요.

python

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution:
    def countGoodRectangles(self, rectangles: List[List[int]]) -> int:
        res ={}
        maxnum = 0 
        for i in range(len(rectangles)):
            temp = min(rectangles[i][0],rectangles[i][1])
            maxnum = max(maxnum,temp)
            if temp not in res :
                res[temp] = 1
            else :
                res[temp] += 1
        return res[maxnum]
                     

6. 결과 및 후기, 개선점

필요시 c++로 짜드립니다.

설명이 필요하다면 댓글을 달아주세요.

This post is licensed under CC BY 4.0 by the author.