You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
949 B

import java.util.Arrays;
public class L0455 {
public static void main(String[] args) throws Exception {
int[] g = { 10, 9, 8, 7 };
int[] s = { 5, 6, 7, 8, 6 };
System.out.print(findContentChildren(g, s));
}
public static int findContentChildren(int[] g, int[] s) {
int i, j;
int g_num = g.length;
int s_num = s.length;
Arrays.sort(g);
Arrays.sort(s);
int sum = 0;
int a = 0;
int position = 0;
for (i = 0; i < s_num; i++) {
for (j = position; j < g_num; j++) {
a += 1;
if (s[i] >= g[j]) {
// System.out.println(s[i]);
// System.out.println(g[j]);
sum = sum + 1;
position = j + 1;
j = g_num;
}
}
}
// System.out.println(a);
return sum;
}
}