From d5374f294d7c237ea7728276367c3a73c4f8ba60 Mon Sep 17 00:00:00 2001 From: Ignacio Herrera Date: Tue, 2 Jan 2024 20:45:57 -0300 Subject: [PATCH] Leetcode/455 and 2610 --- .vscode/settings.json | 1 - README.md | 4 +++- problems/leetcode/2610/solution.js | 25 +++++++++++++++++++++++++ problems/leetcode/455/solution.js | 21 +++++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 problems/leetcode/2610/solution.js create mode 100644 problems/leetcode/455/solution.js diff --git a/.vscode/settings.json b/.vscode/settings.json index a4dfcba..311b434 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,5 @@ { "workbench.colorTheme": "GitHub Dark Colorblind (Beta)", - "workbench.activityBar.visible": true, "workbench.colorCustomizations": { "editor.lineHighlightBackground": "#1073cf2d", "editor.lineHighlightBorder": "#9fced11f", diff --git a/README.md b/README.md index 6f92fba..62451b7 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,7 @@ - [414: Third maximum number](problems/leetcode/414) - Easy - Array - [433: Minimum genetic mutation](problems/leetcode/433) - [448: Find all numbers disappeared in an array](problems/leetcode/448) - Easy - Array +- [455: Assign cookies](problems/leetcode/455) - Easy - Array - [485: Max consecutive ones](problems/leetcode/485) - Array - [487: Max consecutive ones II](problems/leetcode/487) - Medium - Array - [515: Find largest value in each tree row](problems/leetcode/515) - Medium - Tree @@ -226,5 +227,6 @@ - [1832: Check if the sentence is pangram](problems/leetcode/1832) - [1926: Nearest exit from entrance in maze](problems/leetcode/1926) - [2095: Delete the middle node of a linked list](problems/leetcode/2095) -- [2225: Find players with zero or one losses](problems/leetcode/2225) - Map - [2131: Longest palindrome by concatenating two letter words](problems/leetcode/2131) +- [2225: Find players with zero or one losses](problems/leetcode/2225) - Map +- [2610: Convert an array into a 2d array with conditions](problems/leetcode/2610) - Medium - Array diff --git a/problems/leetcode/2610/solution.js b/problems/leetcode/2610/solution.js new file mode 100644 index 0000000..04acd74 --- /dev/null +++ b/problems/leetcode/2610/solution.js @@ -0,0 +1,25 @@ +/** + * + * @param {number[]} nums + * @return {number[][]} + */ +const findMatrix = (nums) => { + const freq = {}; + const res = []; + + nums.forEach((num) => { + if (freq[num] !== undefined) { + freq[num] = freq[num] + 1; + } else { + freq[num] = 0; + } + + if (res[freq[num]]) { + res[freq[num]].push(num); + } else { + res[freq[num]] = [num]; + } + }); + + return res; +} diff --git a/problems/leetcode/455/solution.js b/problems/leetcode/455/solution.js new file mode 100644 index 0000000..e57615a --- /dev/null +++ b/problems/leetcode/455/solution.js @@ -0,0 +1,21 @@ +/** + * + * @param {number[]} g + * @param {number[]} s + * @return {number} + */ +const findContentChildren = (g, s) => { + const factors = [...g].sort((a, b) => a - b); + const cookieSizes = [...s].sort((a, b) => a - b); + let child = 0; + let cookie = 0; + + while (child < factors.length && cookie < cookieSizes.length) { + if (factors[child] <= cookieSizes[cookie]) { + child++; + } + cookie++; + } + + return child; +}