[프로그래머스] 귤 고르기 - 구현

JinUk Lee·2023년 7월 4일
0

프로그래머스

목록 보기
36/47

https://school.programmers.co.kr/learn/courses/30/lessons/138476


from collections import Counter

def solution(k, tangerine):

    A = dict(Counter(tangerine))
    B = list(A.values())
    B.sort()
    temt = 0 # 귤의 갯수
    cnt=0 # 귤 종류의 갯수
    while True:
        C = B.pop()
        cnt+=1
        temt += C
        if temt >= k:
            break


    return cnt

Counter 클래스로 귤의 갯수를 구한다.

귤의 갯수를 정렬하고 가장 큰 값부터 더해가면서 K 보다 크거나 같아질때 더해진 귤 종류의 갯수를 구한다.

profile
개발자 지망생

0개의 댓글