Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 12. 27. 23:45

https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/

 

Maximum Bags With Full Capacity of Rocks - LeetCode

Maximum Bags With Full Capacity of Rocks - You have n bags numbered from 0 to n - 1. You are given two 0-indexed integer arrays capacity and rocks. The ith bag can hold a maximum of capacity[i] rocks and currently contains rocks[i] rocks. You are also give

leetcode.com

생각보다 간단한 문제

class Solution:
    def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
        for i in range(len(capacity)):
            capacity[i] -= rocks[i]
        i = 0
        capacity.sort()

        while i < len(capacity) and additionalRocks - capacity[i] >= 0:
            additionalRocks -= capacity[i]
            i += 1
        return i
반응형