-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path455.分发饼干.java
47 lines (42 loc) · 1.02 KB
/
455.分发饼干.java
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
/*
* @lc app=leetcode.cn id=455 lang=java
*
* [455] 分发饼干
*/
// @lc code=start
class Solution {
public int findContentChildren(int[] g, int[] s) {
// mine
// int result = 0;
// Arrays.sort(g);
// Arrays.sort(s);
// int j = 0;
// for (int i = 0 ; i < g.length ; i++) {
// while (j < s.length) {
// if (s[j] >= g[i]) {
// result++;
// j++;
// break;
// }
// j++;
// }
// if (j >= s.length) break;
// }
// return result;
// Solution from Nick White
Arrays.sort(g);
Arrays.sort(s);
int aPoint = 0;
int bPoint = 0;
while (aPoint < g.length && bPoint < s.length) {
if (g[aPoint] <= s[bPoint]) {
aPoint++;
bPoint++;
} else {
bPoint++;
}
}
return aPoint;
}
}
// @lc code=end