Skip to content

Commit 10ef206

Browse files
committed
455. 分发饼干
1 parent 891b970 commit 10ef206

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/com/gatsby/_455AssignCookies.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.gatsby;
2+
3+
import java.util.Arrays;
4+
5+
/**
6+
* @ClassName: _455AssignCookies
7+
* @Description:
8+
* @author: Gatsby
9+
* @date: 2022/7/25 13:34
10+
*/
11+
12+
public class _455AssignCookies {
13+
public int findContentChildren(int[] appetite, int[] biscuits) {
14+
Arrays.sort(appetite);
15+
Arrays.sort(appetite);
16+
Arrays.sort(biscuits);
17+
int children = 0;
18+
int a = appetite.length;
19+
int b = biscuits.length;
20+
for (int i = 0, j = 0; i < a && j < b; ++i, ++j) {
21+
while (j < b && biscuits[j] < appetite[i]) ++j;
22+
if (j < b) children++;
23+
}
24+
return children;
25+
}
26+
}
27+
28+

0 commit comments

Comments
 (0)