и посмотреть медиа
JavaScript LeetCode
и посмотреть медиа
Tareas y soluciones de LeetCode en JavaScript. Ideal para la preparación de entrevistas y la mejora de habilidades de algoritmo.
Tareas y soluciones de LeetCode en JavaScript. Ideal para la preparación de entrevistas y la mejora de habilidades de algoritmo.
bot de IA para clonar texto a voz y voz en Telegram. Cree audio utilizando la red neuronal de forma rápida y fácil.
El canal está dedicado a resolver las tareas de LeetCode en JavaScript. Contiene ejemplos de códigos para problemas algoritmos populares que se encuentran frecuentemente en entrevistas. Los materiales ayudarán a dominar estructuras de datos, clasificación, programación dinámica y otros temas clave.
Задача: 1102. Path With Maximum Minimum Value Сложность: medium Дана целочисленная матрица grid размером m x n. Верните максимальное значение пути, начинающегося в (0, 0) и заканчивающегося в (m - 1, n - 1), двигаясь в 4 кардинальных направлениях. Значение пути определяется минимальным числом на этом пути. Пример: Input: grid = [[5,4,5],[1,2,6],[7,4,6]] Output: 4 Explanation: The path with the maximum score is highlighted in yellow. 👨💻 Алгоритм: 1⃣Начните с оценки curScore = min(grid[0][0], grid[m-1][n-1]), где m и n - общее количество строк и столбцов входной матрицы. 2⃣Выполните BFS на матрице и проверьте, существует ли путь, где все значения больше или равны curScore: Используйте очередь (deque) для хранения всех непосещенных ячеек со значением, большим или равным curScore. Извлекайте ячейку из начала очереди, проверяйте, есть ли у нее непосещенные соседние ячейки, и добавляйте их в конец очереди. Если успешно достигли правой нижней ячейки, значит путь существует. Если очередь опустела до достижения правой нижней ячейки, пути не существует. 3⃣Если пути не существует, что означает, что curScore слишком велик, уменьшите его на 1 и повторите шаг 2. В противном случае, верните curScore как ответ. 😎 Решение: var maximumMinimumPath = function(grid) { const R = grid.length, C = grid[0].length let curScore = Math.min(grid[0][0], grid[R - 1][C - 1]) while (curScore >= 0) { if (pathExists(grid, curScore)) { return curScore } curScore-- } return -1 } var pathExists = function(grid, curScore) { const R = grid.length, C = grid[0].length const visited = Array.from({ length: R }, () => Array(C).fill(false)) const dq = [[0, 0]] visited[0][0] = true const push = (row, col) => { if (row >= 0 && col >= 0 && row < R && col < C && !visited[row][col] && grid[row][col] >= curScore) { dq.push([row, col]) visited[row][col] = true } } while (dq.length > 0) { const [curRow, curCol] = dq.shift() if (curRow == R - 1 && curCol == C - 1) { return true } push(curRow + 1, curCol) push(curRow - 1, curCol) push(curRow, curCol + 1) push(curRow, curCol - 1) } return false } Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаSolo los usuarios registrados pueden compartir su opinión.
¡Sé el primero en compartir tu experiencia con este recurso!