We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d8c2a16 commit 8e8e078Copy full SHA for 8e8e078
assign-cookies/index.ts
@@ -1,16 +1,14 @@
1
function findContentChildren(g: number[], s: number[]): number {
2
- g.sort((a, b) => a - b);
3
- s.sort((a, b) => a - b);
4
- const m = g.length, n = s.length;
5
- let count = 0;
6
- for (let i = 0, j = 0; i < m && j < n; i++, j++) {
7
- while (j < n && g[i] > s[j]) {
8
- j++;
+ 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++
9
+ index--
10
}
- if (j < n) {
11
- count++;
12
- }
13
14
- return count;
+ }
+ return result
15
16
export default findContentChildren
0 commit comments