Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ac351e1

Browse files
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)

AltStyle によって変換されたページ (->オリジナル) /