重新分装苹果
重新分装苹果
#resource / algorithm
#type / snippet
#status / evergreen
#source / leetcode
#algo / greedy
[!info] related notes 算法面试题型 MOC 贪心算法
重新分装苹果
题目
题解
贪心算法
var minimumBoxes = function (apple, capacity) {
let res = 0;
let sum = apple.reduce((acc, cur) =>
acc + cur, 0
)
capacity = capacity.sort((a, b) => b - a)
for (const cap of capacity) {
sum -= cap;
res++;
if (sum <= 0) {
return res;
}
}
return res;
};