-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathLeetCode_455_18.java
More file actions
47 lines (37 loc) · 911 Bytes
/
LeetCode_455_18.java
File metadata and controls
47 lines (37 loc) · 911 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package Week_04.id_18;
import java.util.Arrays;
/**
* @author LiveForExperience
* @date 2019/6/26 12:59
*/
public class LeetCode_455_18 {
public int findContentChildren(int[] g, int[] s) {
Arrays.sort(g);
Arrays.sort(s);
int j = 0, count = 0, sl = s.length;
for (int value : g) {
while (j < sl) {
if (value <= s[j++]) {
count++;
break;
}
}
if (j == sl) {
break;
}
}
return count;
}
public int findContentChildren1(int[] g, int[] s) {
Arrays.sort(g);
Arrays.sort(s);
int gi = 0, si = 0, gl = g.length, sl = s.length;
while (gi < gl && si < sl) {
if (g[gi] <= s[si]) {
gi++;
}
si++;
}
return gi;
}
}