

- Главная
- Каталог
- Интернет технологии
- JavaScript | LeetCode
JavaScript | LeetCode
Разбираем задачи с LeetCode на языке программирования JavaScript
Статистика канала
Полная статистикаchevron_right
Input: x = 4
Output: 2
Explanation: The square root of 4 is 2, so we return 2.{}
var mySqrt = function (x) {
if (x < 2) return x;
let num;
let pivot,
left = 2,
right = Math.floor(x / 2);
while (left <= right) {
pivot = left + Math.floor((right - left) / 2);
num = pivot * pivot;
if (num > x) right = pivot - 1;
else if (num < x) left = pivot + 1;
else return pivot;
}
return right;
};{}
Ставь 👍 и забирай 📚 Базу знаний
Input: root = [1,2,3,4], x = 4, y = 3
Output: false{}
class TreeNode {
constructor(val = 0, left = null, right = null) {
this.val = val;
this.left = left;
this.right = right;
}
}
var isCousins = function(root, x, y) {
let parentX = null, parentY = null;
let depthX = -1, depthY = -1;
function dfs(node, parent, depth) {
if (!node) return;
if (node.val === x) {
parentX = parent;
depthX = depth;
} else if (node.val === y) {
parentY = parent;
depthY = depth;
} else {
dfs(node.left, node, depth + 1);
dfs(node.right, node, depth + 1);
}
}
dfs(root, null, 0);
return depthX === depthY && parentX !== parentY;
};{}
Ставь 👍 и забирай 📚 Базу знаний
Input: timeSeries = [1,4], duration = 2
Output: 4
Explanation: Teemo's attacks on Ashe go as follows:
- At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.
- At second 4, Teemo attacks, and Ashe is poisoned for seconds 4 and 5.
Ashe is poisoned for seconds 1, 2, 4, and 5, which is 4 seconds in total.{}
class Solution {
findPoisonedDuration(timeSeries, duration) {
const n = timeSeries.length;
if (n === 0) return 0;
let total = 0;
for (let i = 0; i < n - 1; i++) {
total += Math.min(timeSeries[i + 1] - timeSeries[i], duration);
}
return total + duration;
}
}{}
Ставь 👍 и забирай 📚 Базу знаний
Input: root = [4,2,6,1,3,5,7], target = 2
Output: [[2,1],[4,3,6,null,null,5,7]]{}
function TreeNode(val) {
this.val = val;
this.left = this.right = null;
}
var splitBST = function(root, target) {
if (!root) {
return [null, null];
}
if (root.val > target) {
let left = splitBST(root.left, target);
root.left = left[1];
return [left[0], root];
} else {
let right = splitBST(root.right, target);
root.right = right[0];
return [root, right[1]];
}
};{}
Ставь 👍 и забирай 📚 Базу знаний
Input: arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8]
Output: [1,5]
Explanation: Only 1 and 5 appeared in the three arrays.{}
class Solution {
arraysIntersection(arr1, arr2, arr3) {
const counter = new Map();
for (const e of arr1) counter.set(e, (counter.get(e) || 0) + 1);
for (const e of arr2) counter.set(e, (counter.get(e) || 0) + 1);
for (const e of arr3) counter.set(e, (counter.get(e) || 0) + 1);
const ans = [];
for (const [key, value] of counter) {
if (value === 3) ans.push(key);
}
return ans;
}
}{}
Ставь 👍 и забирай 📚 Базу знанийОтзывы канала
Каталог Телеграм-каналов для нативных размещений
JavaScript | LeetCode — это Telegam канал в категории «Интернет технологии», который предлагает эффективные форматы для размещения рекламных постов в Телеграмме. Количество подписчиков канала в 9.6K и качественный контент помогают брендам привлекать внимание аудитории и увеличивать охват. Рейтинг канала составляет 5.6, количество отзывов – 0, со средней оценкой 0.0.
Вы можете запустить рекламную кампанию через сервис Telega.in, выбрав удобный формат размещения. Платформа обеспечивает прозрачные условия сотрудничества и предоставляет детальную аналитику. Стоимость размещения составляет 1818.18 ₽, а за 5 выполненных заявок канал зарекомендовал себя как надежный партнер для рекламы в TG. Размещайте интеграции уже сегодня и привлекайте новых клиентов вместе с Telega.in!
Вы снова сможете добавить каналы в корзину из каталога
Комментарий