Skip to content

Commit 72f877e

Browse files
authored
Create Fruits Into Baskets II.java
1 parent 7e86b13 commit 72f877e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Easy/Fruits Into Baskets II.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public int numOfUnplacedFruits(int[] fruits, int[] baskets) {
3+
int count = 0;
4+
for (int fruit : fruits) {
5+
int idx = -1;
6+
for (int i = 0; i < baskets.length; i++) {
7+
if (baskets[i] >= fruit) {
8+
idx = i;
9+
break;
10+
}
11+
}
12+
if (idx == -1) {
13+
count++;
14+
} else {
15+
baskets[idx] = -1;
16+
}
17+
}
18+
return count;
19+
}
20+
}

0 commit comments

Comments
 (0)