leetcode-3074. Apple Redistribution into Boxes

Youngsun Joung·2025년 12월 24일

Leetcode

목록 보기
71/91

1. 문제 소개

3074. Apple Redistribution into Boxes

2. 나의 풀이

쉬운 문제인 만큼 간단하게 풀 수 있었다.
시간복잡도는 O(klogk)O(k\, \text{log} k)이다.

class Solution:
    def minimumBoxes(self, apple: List[int], capacity: List[int]) -> int:
        capacity.sort(reverse=True)                      # 수용량을 내림차순 정렬(큰 상자부터 사용)
        sum_apple = sum(apple)                           # 옮겨야 하는 사과 총합 계산

        for i, c in enumerate(capacity):                 # 큰 수용량 상자부터 하나씩 사용
            sum_apple -= c                               # 현재 상자의 수용량만큼 사과를 담는다고 가정(남은 사과 감소)
            if sum_apple <= 0:                           # 남은 사과가 0 이하이면 모두 담을 수 있음
                return i + 1                             # 사용한 상자 개수(0-index이므로 i+1) 반환

3. 다른 풀이

거의 비슷한 풀이들이었다.

4. 마무리

계속 공부하자.

profile
Junior AI Engineer

0개의 댓글