Greedy Algorithm Problems

Made by Mike_Zhang


数据结构与算法题主题:


Assign Cookies

LeetCode Problem #455

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution {
public int findContentChildren(int[] g, int[] s) {
Arrays.sort(g);
Arrays.sort(s);
int sizeG = g.length;
int sizeS = s.length;
int ptrG = 0;
int ptrS = 0;
int out = 0;
while (ptrG < sizeG && ptrS < sizeS) {
if (g[ptrG] <= s[ptrS]) {
ptrG++;
ptrS++;
out++;
}
else {
ptrS++;
}
}
return out;
}
}

2022-10-07


Last updated on 2022-11-25


References

Greedy - LeetCode


写在最后

Greedy Algorithm 相关的知识会继续学习,继续更新.
最后,希望大家一起交流,分享,指出问题,谢谢!


原创文章,转载请标明出处
Made by Mike_Zhang




感谢你的支持

Greedy Algorithm Problems
https://ultrafish.io/post/greedy-problems/
Author
Mike_Zhang
Posted on
November 25, 2022
Licensed under