-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetCode455.java
More file actions
31 lines (28 loc) · 837 Bytes
/
LeetCode455.java
File metadata and controls
31 lines (28 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.Arrays;
public class LeetCode455 {
public static void main(String[] args) {
// 输入: g = [1,2,3], s = [1,1]
// 输出: 1
System.out.println(new Solution455().findContentChildren(new int[] { 1, 2, 3 }, new int[] { 1, 1 }));
// 输入: g = [1,2], s = [1,2,3]
// 输出: 2
System.out.println(new Solution455().findContentChildren(new int[] { 1, 2 }, new int[] { 1, 2, 3 }));
}
}
class Solution455 {
public int findContentChildren(int[] g, int[] s) {
Arrays.sort(g);
Arrays.sort(s);
int p1 = 0;
int p2 = 0;
while (p1 < g.length && p2 < s.length) {
if (g[p1] <= s[p2]) {
p1++;
p2++;
} else {
p2++;
}
}
return p1;
}
}