Skip to content

Commit 5698bbd

Browse files
authored
Merge pull request #35 from Nishat30/main
solved 3477. Fruits Into Baskets II in C++ #32
2 parents 9722419 + 6a1f654 commit 5698bbd

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

3477. Fruits Into Baskets II

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public:
3+
int numOfUnplacedFruits(vector<int>& fruits, vector<int>& baskets) {
4+
int unplaced = 0;
5+
int n = fruits.size();
6+
int m = baskets.size();
7+
8+
for (int i = 0; i < n; i++) {
9+
bool placed = false;
10+
for (int j = 0; j < m; j++) {
11+
if (baskets[j] >= fruits[i]) {
12+
baskets[j] = -1;
13+
placed = true;
14+
break;
15+
}
16+
}
17+
18+
if (!placed) {
19+
unplaced++;
20+
}
21+
}
22+
23+
return unplaced;
24+
}
25+
};

0 commit comments

Comments
 (0)