Logo
TGCATALOG
Catálogo Selecciones Blog
Golang  LeetCode

Golang LeetCode

Tareas de LeetCode en Golang. Soluciones con código y explicaciones.

Sin valoraciones
376
02.12.2026
376
02.12.2026
Sin valoraciones
376
02.12.2026
Redirección segura vía bot
О канале

Tareas de LeetCode en Golang. Soluciones con código y explicaciones.

Подписчиков —
Тематика Tecnología
Ссылка @easy_golang_task

También te recomendamos

Kekaton AI  Voz en off y clon de voz
Kekaton AI Voz en off y clon de voz
Bot

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.

Descripción

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.

Últimas publicaciones

Golang  LeetCode
Golang LeetCode
🔒Открыть пост
и посмотреть медиа
Задача: 1245. Tree Diameter Сложность: medium Диаметр дерева - это количество ребер в самом длинном пути в этом дереве. Имеется неориентированное дерево из n узлов, помеченных от 0 до n - 1. Вам дан двумерный массив edges, где edges.length == n - 1 и edges[i] = [ai, bi] означает, что между узлами ai и bi в дереве есть неориентированное ребро. Верните диаметр дерева. Пример: Input: edges = [[0,1],[0,2]] Output: 2 👨💻 Алгоритм: 1⃣Построение графа: Используем представление графа в виде списка смежности. 2⃣Поиск самой удаленной вершины (DFS1): Запускаем DFS от произвольной вершины (например, 0) для нахождения самой удаленной вершины от нее. 3⃣Поиск диаметра (DFS2): Запускаем DFS от найденной на предыдущем шаге самой удаленной вершины и находим самую удаленную вершину от нее. Это расстояние и будет диаметром дерева.reset(playerId): Устанавливаем счет игрока в 0. 😎 Решение: package main func treeDiameter(edges [][]int) int {     if len(edges) == 0 {         return 0     }     graph := make(map[int][]int)     for _, edge := range edges {         graph[edge[0]] = append(graph[edge[0]], edge[1])         graph[edge[1]] = append(graph[edge[1]], edge[0])     }     var farthestNode int     var dfs func(int, int) int     dfs = func(node int, parent int) int {         maxDepth := 0         for _, neighbor := range graph[node] {             if neighbor != parent {                 depth := dfs(neighbor, node)                 if depth+1 > maxDepth {                     maxDepth = depth + 1                     farthestNode = neighbor                 }             }         }         return maxDepth     }     dfs(0, -1)     startNode := farthestNode     dfs(startNode, -1)     return dfs(farthestNode, -1) } func main() {} Ставь 👍 и забирай 📚 Базу знаний
Golang LeetCode

Reseñas de canal Golang LeetCode

Inicia sesión para dejar una reseña

Solo los usuarios registrados pueden compartir su opinión.

Aún no hay reseñas

¡Sé el primero en compartir tu experiencia con este recurso!

Recursos similares

Loading
Cambiar a tema claro
Inicio Catálogo Selecciones Blog Entrar