Skip to content

Commit 3088d12

Browse files
authored
Merge pull request #42 from masx200/masx200-patch-1
https://leetcode-cn.com/problems/assign-cookies/
2 parents 0e64838 + 8e8e078 commit 3088d12

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Step 2. Add the dependency
4949

5050
<summary>展开查看</summary>
5151

52+
https://leetcode-cn.com/problems/assign-cookies/
53+
5254
https://leetcode-cn.com/problems/evaluate-the-bracket-pairs-of-a-string/
5355

5456
https://leetcode.cn/problems/find-the-middle-index-in-array/

assign-cookies/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function findContentChildren(g: number[], s: number[]): number {
2+
g = g.sort((a, b) => a - b)
3+
s = s.sort((a, b) => a - b)
4+
let result = 0
5+
let index = s.length - 1
6+
for(let i = g.length - 1; i >= 0; i--) {
7+
if(index >= 0 && s[index] >= g[i]) {
8+
result++
9+
index--
10+
}
11+
}
12+
return result
13+
}
14+
export default findContentChildren

0 commit comments

Comments
 (0)