Skip to content

Commit 8d1f1a4

Browse files
committed
add 3074
1 parent abc188d commit 8d1f1a4

2 files changed

Lines changed: 23 additions & 15 deletions

File tree

javascript/LeetCode/Array/3074.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* 3074. Apple Redistribution into Boxes
3+
*
4+
* 最少需要幾個箱子才能將重新分配的apple裝進去
5+
*
6+
* @param {number[]} apple
7+
* @param {number[]} capacity
8+
* @return {number}
9+
*/
10+
var minimumBoxes = function(apple, capacity) {
11+
// sort box desc
12+
capacity.sort((a,b) => b - a);
13+
let sum = apple.reduce((a,b) => a + b,0);
14+
let ans = 0;
15+
while(sum > 0){
16+
sum -= capacity[ans++];
17+
}
18+
return ans;
19+
20+
};
21+
let apple = [5,5,5], capacity = [2,4,2,7];
22+
// 4
23+
console.log(minimumBoxes(apple,capacity))

javascript/index.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,18 +1159,3 @@ var specialTriplets = function(nums) {
11591159
*/
11601160
// console.log(specialTriplets(nums));
11611161

1162-
/**
1163-
* 3074. Apple Redistribution into Boxes
1164-
*
1165-
* @param {number[]} apple
1166-
* @param {number[]} capacity
1167-
* @return {number}
1168-
*/
1169-
var minimumBoxes = function(apple, capacity) {
1170-
// sort box desc
1171-
capacity.sort((a,b) => a - b);
1172-
console.log(capacity)
1173-
};
1174-
let apple = [5,5,5], capacity = [2,4,2,7];
1175-
// 4
1176-
console.log(minimumBoxes(apple,capacity))

0 commit comments

Comments
 (0)