Skip to content

Commit 2641f1b

Browse files
committed
455. 分发饼干
1 parent 74e8519 commit 2641f1b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
|451|[根据字符出现频率排序](https://leetcode.cn/problems/sort-characters-by-frequency/)|[JavaScript](./algorithms/sort-characters-by-frequency.js)|Medium|
140140
|453|[最小操作次数使数组元素相等](https://leetcode.cn/problems/minimum-moves-to-equal-array-elements/)|[JavaScript](./algorithms/minimum-moves-to-equal-array-elements.js)|Easy|
141141
|454|[四数相加 II](https://leetcode.cn/problems/4sum-ii/)|[JavaScript](./algorithms/4sum-ii.js)|Medium|
142+
|455|[分发饼干](https://leetcode.cn/problems/assign-cookies/)|[JavaScript](./algorithms/assign-cookies.js)|Easy|
142143
|485|[最大连续 1 的个数](https://leetcode.cn/problems/max-consecutive-ones/)|[JavaScript](./algorithms/max-consecutive-ones.js)|Easy|
143144
|491|[递增子序列](https://leetcode.cn/problems/non-decreasing-subsequences/)|[JavaScript](./algorithms/non-decreasing-subsequences.js)|Medium|
144145
|495|[提莫攻击](https://leetcode.cn/problems/teemo-attacking/)|[JavaScript](./algorithms/teemo-attacking.js)|Easy|

algorithms/assign-cookies.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* 455. 分发饼干
3+
* @param {number[]} g
4+
* @param {number[]} s
5+
* @return {number}
6+
*/
7+
var findContentChildren = function (g, s) {
8+
g.sort((a, b) => a - b);
9+
s.sort((a, b) => a - b);
10+
11+
let j = 0,
12+
i = 0;
13+
while (j < s.length && i < g.length) {
14+
if (s[j] >= g[i]) {
15+
i++;
16+
}
17+
j++;
18+
}
19+
return i;
20+
};

0 commit comments

Comments
 (0)