
3074. Apple Redistribution into Boxes
쉬운 문제인 만큼 간단하게 풀 수 있었다.
시간복잡도는 이다.
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) 반환

거의 비슷한 풀이들이었다.
계속 공부하자.