и посмотреть медиа
Golang LeetCode
и посмотреть медиа
Tareas de LeetCode en Golang. Soluciones con código y explicaciones.
Tareas de LeetCode en Golang. Soluciones con código y explicaciones.
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.
Canal con soluciones para tareas populares de LeetCode en Go. Concéntrate en algoritmos optimizados, uso eficiente de memoria y código idiomático. Ayuda a preparar entrevistas técnicas en empresas que utilizan Golang.
Задача: 1424. Diagonal Traverse II Сложность: medium Дан двумерный целочисленный массив nums, верните все элементы nums в диагональном порядке. Пример: Input: nums = [[1,2,3,4,5],[6,7],[8],[9,10,11],[12,13,14,15,16]] Output: [1,6,2,8,7,3,9,4,12,10,5,13,11,14,15,16] 👨💻 Алгоритм: 1⃣Инициализируйте очередь с (0, 0) и список ответов ans. 2⃣Пока очередь не пуста: Извлеките (row, col) из очереди. Добавьте nums[row][col] в ans. Если col == 0 и row + 1 в пределах массива, добавьте (row + 1, col) в очередь. Если col + 1 в пределах текущей строки, добавьте (row, col + 1) в очередь. 3⃣Верните ans. 😎 Решение: func findDiagonalOrder(nums [][]int) []int { queue := []struct{ row, col int }{{0, 0}} ans := []int{} for len(queue) > 0 { row, col := queue[0].row, queue[0].col queue = queue[1:] ans = append(ans, nums[row][col]) if col == 0 && row + 1 < len(nums) { queue = append(queue, struct{ row, col int }{row + 1, col}) } if col + 1 < len(nums[row]) { queue = append(queue, struct{ row, col int }{row, col + 1}) } } return ans } Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаSolo los usuarios registrados pueden compartir su opinión.
¡Sé el primero en compartir tu experiencia con este recurso!