FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/Week_04/id_142/LeetCode_455_142.java at master · feixiangcode/algorithm · GitHub
feixiangcode
/
algorithm
Public
forked from
algorithm001/algorithm
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm
/
Week_04
/
id_142
/
LeetCode_455_142.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (26 loc) · 960 Bytes
Breadcrumbs
algorithm
/
Week_04
/
id_142
/
LeetCode_455_142.java
Copy path
File metadata and controls
28 lines (26 loc) · 960 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
util
.
Arrays
;
class
Solution
{
public
int
findContentChildren
(
int
[]
g
,
int
[]
s
) {
if
(
g
==
null
||
s
==
null
) {
return
0
;
}
int
max
=
0
;
Arrays
.
sort
(
g
);
Arrays
.
sort
(
s
);
int
cursor
=
0
;
// assign cookies from the child who is easiest to be contented
for
(
int
greedFactor
:
g
) {
// find the cookie that can content the current child
while
(
cursor
<
s
.
length
) {
// for the next child, check cookies starting from cursor++
// because the cookies that are smaller than the current one can't content the next child
int
cookieSize
=
s
[
cursor
++];
if
(
cookieSize
>=
greedFactor
) {
max
++;
// find the smallest cookie that can content this child.
break
;
// move to the next child
}
}
}
return
max
;
}
}
Back
|
FazBrowse Home
|
New Git URL