diff --git a/README.md b/README.md index 1b1be528..ed0c0ed3 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,8 @@ Step 2. Add the dependency 展开查看 +https://leetcode-cn.com/problems/assign-cookies/ + https://leetcode-cn.com/problems/evaluate-the-bracket-pairs-of-a-string/ https://leetcode.cn/problems/find-the-middle-index-in-array/ diff --git a/assign-cookies/index.ts b/assign-cookies/index.ts new file mode 100644 index 00000000..1914c287 --- /dev/null +++ b/assign-cookies/index.ts @@ -0,0 +1,14 @@ +function findContentChildren(g: number[], s: number[]): number { + g = g.sort((a, b) => a - b) + s = s.sort((a, b) => a - b) + let result = 0 + let index = s.length - 1 + for(let i = g.length - 1; i >= 0; i--) { + if(index >= 0 && s[index] >= g[i]) { + result++ + index-- + } + } + return result +} +export default findContentChildren