File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1114
1114
1190|[ Reverse Substrings Between Each Pair of Parentheses] ( ./solutions/1190-reverse-substrings-between-each-pair-of-parentheses.js ) |Medium|
1115
1115
1191|[ K-Concatenation Maximum Sum] ( ./solutions/1191-k-concatenation-maximum-sum.js ) |Medium|
1116
1116
1192|[ Critical Connections in a Network] ( ./solutions/1192-critical-connections-in-a-network.js ) |Hard|
1117
+ 1196|[ How Many Apples Can You Put into the Basket] ( ./solutions/1196-how-many-apples-can-you-put-into-the-basket.js ) |Easy|
1117
1118
1200|[ Minimum Absolute Difference] ( ./solutions/1200-minimum-absolute-difference.js ) |Easy|
1118
1119
1201|[ Ugly Number III] ( ./solutions/1201-ugly-number-iii.js ) |Medium|
1119
1120
1202|[ Smallest String With Swaps] ( ./solutions/1202-smallest-string-with-swaps.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1196. How Many Apples Can You Put into the Basket
3
+ * https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket/
4
+ * Difficulty: Easy
5
+ *
6
+ * You have some apples and a basket that can carry up to 5000 units of weight.
7
+ *
8
+ * Given an integer array weight where weight[i] is the weight of the ith apple,
9
+ * return the maximum number of apples you can put in the basket.
10
+ */
11
+
12
+ /**
13
+ * @param {number[] } weight
14
+ * @return {number }
15
+ */
16
+ var maxNumberOfApples = function ( weight ) {
17
+ weight . sort ( ( a , b ) => a - b ) ;
18
+
19
+ let totalWeight = 0 ;
20
+ let result = 0 ;
21
+
22
+ for ( const appleWeight of weight ) {
23
+ if ( totalWeight + appleWeight <= 5000 ) {
24
+ totalWeight += appleWeight ;
25
+ result ++ ;
26
+ } else {
27
+ break ;
28
+ }
29
+ }
30
+
31
+ return result ;
32
+ } ;
You can’t perform that action at this time.
0 commit comments