и посмотреть медиа
JavaScript | LeetCode
и посмотреть медиа
LeetCode tasks and solutions in JavaScript. Ideal for interview preparation and improving algorithm skills.
LeetCode tasks and solutions in JavaScript. Ideal for interview preparation and improving algorithm skills.
AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.
The channel is dedicated to solving LeetCode tasks in JavaScript. It contains code examples for popular algorithmic problems frequently encountered in interviews. The materials will help master data structures, sorting, dynamic programming, and other key topics. Suitable for junior and middle developers looking to improve their skills.
Задача: 646. Maximum Length of Pair Chain Сложность: medium Вам дан массив из n пар, где pairs[i] = [lefti, righti] и lefti < righti. Пара p2 = [c, d] следует за парой p1 = [a, b], если b < c. Таким образом можно построить цепочку пар. Верните самую длинную цепочку, которую можно составить. Вам не нужно использовать все заданные интервалы. Вы можете выбирать пары в любом порядке. Пример: Input: nums = [1,2,2,4] Output: [2,3] 👨💻 Алгоритм: 1⃣Отсортируйте пары по второму элементу каждой пары (righti). 2⃣Используйте динамическое программирование или жадный алгоритм, чтобы построить цепочку максимальной длины. 3⃣Переберите отсортированные пары и выберите пары, которые могут следовать одна за другой, увеличивая длину цепочки. 😎 Решение: function findLongestChain(pairs) { pairs.sort((a, b) => a[1] - b[1]); let currentEnd = Number.MIN_SAFE_INTEGER; let count = 0; for (const pair of pairs) { if (currentEnd < pair[0]) { currentEnd = pair[1]; count++; } } return count; } Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаOnly registered users can share their opinion.
Be the first to share your impression of this resource!