본문 바로가기

IT/코딩테스트

[Leetcode] 3074. Apple Redistribution into Boxes

728x90

https://leetcode.com/problems/apple-redistribution-into-boxes

class Solution:
    def minimumBoxes(self, apple: List[int], capacity: List[int]) -> int:
        sum = 0
        for n in apple:
            sum += n
        print('sum: ' + str(sum))
        
        capacity.sort(reverse=True)
        
        c_sum = 0
        for i in range(len(capacity)):
            c_sum += capacity[i]
            if c_sum >= sum:
                break
    
        return i + 1
728x90