Logo
TGCATALOG
Catalog Collections Blog
Golang | LeetCode

Golang | LeetCode

LeetCode tasks in Golang. Solutions with code and explanations.

No ratings
374
01.12.2026
374
01.12.2026
No ratings
374
01.12.2026
Safe redirect via bot
О канале

LeetCode tasks in Golang. Solutions with code and explanations.

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

We also recommend

Kekaton AI | Voiceover and voice clone
Kekaton AI | Voiceover and voice clone
Bot

AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.

Description

Channel with solutions to popular LeetCode tasks in Go. Focus on optimized algorithms, efficient memory usage, and idiomatic code. Helps prepare for technical interviews in companies that use Golang.

Latest posts

Golang | LeetCode
Golang | LeetCode
🔒Открыть пост
и посмотреть медиа
Задача: 1361. Validate Binary Tree Nodes Сложность: easy У вас есть n узлов бинарного дерева, пронумерованных от 0 до n-1, где узел i имеет двух детей: leftChild[i] и rightChild[i]. Верните true, если и только если все заданные узлы образуют ровно одно допустимое бинарное дерево. Если у узла i нет левого ребенка, то leftChild[i] будет равен -1, аналогично для правого ребенка. Обратите внимание, что узлы не имеют значений и мы используем только номера узлов в этой задаче. Пример: Input: n = 4, leftChild = [1,-1,3,-1], rightChild = [2,-1,-1,-1] Output: true 👨💻 Алгоритм: 1⃣Проверка количества родителей для каждого узла: Создайте массив для отслеживания количества родителей для каждого узла. Проходите через leftChild и rightChild, увеличивая счетчик для каждого ребенка. Если какой-либо узел имеет более одного родителя, возвращайте false. 2⃣Поиск корневого узла и проверка на единственное дерево: Найдите корневой узел (узел с нулевым количеством родителей). Если корневых узлов нет или больше одного, верните false. Используйте BFS или DFS, чтобы проверить, что все узлы достижимы от корня и что нет циклов. 3⃣Проверка на достижение всех узлов: Проверьте, что количество посещенных узлов равно n. Если нет, верните false. В противном случае, верните true. 😎 Решение: package main import ( "fmt" ) func validateBinaryTreeNodes(n int, leftChild []int, rightChild []int) bool { parents := make([]int, n) for i := 0; i < n; i++ { if leftChild[i] != -1 { parents[leftChild[i]]++ if parents[leftChild[i]] > 1 { return false } } if rightChild[i] != -1 { parents[rightChild[i]]++ if parents[rightChild[i]] > 1 { return false } } } root := -1 for i := 0; i < n; i++ { if parents[i] == 0 { if root == -1 { root = i } else { return false } } } if root == -1 { return false } visited := make(map[int]struct{}) queue := []int{root} for len(queue) > 0 { node := queue[0] queue = queue[1:] if _, found := visited[node]; found { return false } visited[node] = struct{}{} if leftChild[node] != -1 { queue = append(queue, leftChild[node]) } if rightChild[node] != -1 { queue = append(queue, rightChild[node]) } } return len(visited) == n } func main() { leftChild := []int{1, -1, 3, -1} rightChild := []int{2, -1, -1, -1} fmt.Println(validateBinaryTreeNodes(4, leftChild, rightChild)) // Output: true } Ставь 👍 и забирай 📚 Базу знаний
Golang | LeetCode
FAQ

Open Golang | LeetCode in Telegram and press the Start button. No separate registration is required.

Yes. The service is designed to be straightforward: open the resource, follow the on-screen instructions and start using it.

No. You can use Golang | LeetCode directly in Telegram unless the resource description says otherwise.

Access depends on the resource. Check the current information in Telegram after opening Golang | LeetCode.

The exact features depend on the resource. Open Golang | LeetCode to see its current functions, content and access conditions.

Reviews for channel Golang | LeetCode

Log in to leave a review

Only registered users can share their opinion.

No reviews yet

Be the first to share your impression of this resource!

Similar resources

Loading
Switch to Light Theme
Home Catalog Collections Blog Login