и посмотреть медиа
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.
Задача: 1380. Lucky Numbers in a Matrix Сложность: easy Дана матрица m x n из различных чисел, верните все счастливые числа в матрице в любом порядке. Счастливое число — это элемент матрицы, который является минимальным элементом в своей строке и максимальным в своем столбце. Пример: Input: matrix = [[3,7,8],[9,11,13],[15,16,17]] Output: [15] Explanation: 15 is the only lucky number since it is the minimum in its row and the maximum in its column. 👨💻 Алгоритм: 1⃣Сохраните минимум каждой строки в список rowMin и максимум каждого столбца в список colMax. 2⃣Итерируйте по каждому числу в матрице и проверяйте, равно ли оно rowMin[i] и colMax[j]. 3⃣Если число удовлетворяет условию, добавьте его в список luckyNumbers и верните luckyNumbers. 😎 Решение: var luckyNumbers = function(matrix) { let N = matrix.length; let M = matrix[0].length; let rowMin = []; for (let i = 0; i < N; i++) { let rMin = Math.min(...matrix[i]); rowMin.push(rMin); } let colMax = []; for (let i = 0; i < M; i++) { let cMax = -Infinity; for (let j = 0; j < N; j++) { cMax = Math.max(cMax, matrix[j][i]); } colMax.push(cMax); } let luckyNumbers = []; for (let i = 0; i < N; i++) { for (let j = 0; j < M; j++) { if (matrix[i][j] === rowMin[i] && matrix[i][j] === colMax[j]) { luckyNumbers.push(matrix[i][j]); } } } return luckyNumbers; }; Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаOnly registered users can share their opinion.
Be the first to share your impression of this resource!