2279. Maximum Bags With Full Capacity of Rocks
Question
You have
nbags numbered from0ton - 1. You are given two 0-indexed integer arrayscapacityandrocks. Thei<sup>th</sup>bag can hold a maximum ofcapacity[i]rocks and currently containsrocks[i]rocks. You are also given an integeradditionalRocks, the number of additional rocks you can place in any of the bags.Return* the maximum number of bags that could have full capacity after placing the additional rocks in some bags.*
Solution
计算每个背包的剩余空间,然后进行排序。
按从小到大的顺序依次减少石头的总数。
设置i作为选取石头的计数。每次循环将i增加,直到剩余的石头数量小于0。
如果最后剩下的石头仍然大于等于0,则返回计数。
否则返回计数-1。
Code
1 | class Solution { |
2279. Maximum Bags With Full Capacity of Rocks
https://xuanhe95.github.io/2022/05/22/2279-Maximum-Bags-With-Full-Capacity-of-Rocks/
