-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path455_Assign Cookies
43 lines (34 loc) · 1001 Bytes
/
455_Assign Cookies
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
/*Runtime: 6 ms, faster than 99.95% of Java online submissions for Assign Cookies.
Memory Usage: 40.2 MB, less than 78.57% of Java online submissions for Assign Cookies.*/
class Solution {
public int findContentChildren(int[] g, int[] s) {
Arrays.sort(g);
Arrays.sort(s);
int i = 0;
for(int j=0;i<g.length && j<s.length;j++) {
if(g[i]<=s[j])
i++;
}
return i;
}
}
/*455. Assign Cookies
Runtime: 70 ms, faster than 6.66% of Java online submissions for Assign Cookies.
Memory Usage: 40 MB, less than 93.35% of Java online submissions for Assign Cookies.
class Solution {
public int findContentChildren(int[] g, int[] s) {
Arrays.sort(g);
Arrays.sort(s);
int count=0;
for(int i:g)
for(int j=0;j<=s.length-1;j++){
if(i<=s[j]){
count++;
s[j]=Integer.MIN_VALUE;
break;
}
}
return count;
}
}
*/