Skip to content

Commit ac351e1

Browse files
committed
5072. How Many Apples Can You Put into the Basket
1 parent 9e1be88 commit ac351e1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Runtime: 4 ms
2+
// Memory Usage: 8.9 MB
3+
class Solution {
4+
public:
5+
int maxNumberOfApples(vector<int>& arr) {
6+
sort(arr.begin(), arr.end());
7+
int sum = 0;
8+
int i;
9+
for (i = 0; i < arr.size(); i++) {
10+
if (sum + arr[i] <= 5000) {
11+
sum += arr[i];
12+
} else {
13+
break;
14+
}
15+
}
16+
return i;
17+
}
18+
};

0 commit comments

Comments
 (0)