Skip to content

Commit

Permalink
Leetcode/455 and 2610
Browse files Browse the repository at this point in the history
  • Loading branch information
herrera-ignacio committed Jan 2, 2024
1 parent 92a6e23 commit d5374f2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"workbench.colorTheme": "GitHub Dark Colorblind (Beta)",
"workbench.activityBar.visible": true,
"workbench.colorCustomizations": {
"editor.lineHighlightBackground": "#1073cf2d",
"editor.lineHighlightBorder": "#9fced11f",
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
25 changes: 25 additions & 0 deletions problems/leetcode/2610/solution.js
Original file line number Diff line number Diff line change
@@ -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;
}
21 changes: 21 additions & 0 deletions problems/leetcode/455/solution.js
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit d5374f2

Please sign in to comment.