Logo
TGCATALOG
Catalog Collections Blog
Golang | LeetCode

Golang | LeetCode

LeetCode tasks in Golang. Solutions with code and explanations.

No ratings
376
02.12.2026
376
02.12.2026
No ratings
376
02.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
🔒Открыть пост
и посмотреть медиа
Задача: 1382. Balance a Binary Search Tree Сложность: medium Дан корень бинарного дерева поиска. Верните сбалансированное бинарное дерево поиска с теми же значениями узлов. Если существует более одного ответа, верните любой из них. Бинарное дерево поиска считается сбалансированным, если глубина двух поддеревьев каждого узла никогда не отличается более чем на 1. Пример: Input: root = [1,null,2,null,3,null,4,null,null] Output: [2,1,3,null,null,null,4] Explanation: This is not the only correct answer, [3,1,4,null,2] is also correct. 👨💻 Алгоритм: 1⃣Инициализация. Создайте пустой список inorder для хранения значений узлов после обхода в порядке возрастания. 2⃣Выполнение обхода в порядке возрастания. Обойдите бинарное дерево поиска (BST) и заполните список inorder значениями узлов в отсортированном порядке. 3⃣Перестроение сбалансированного BST. Определите рекурсивную функцию createBalancedBST, которая принимает список inorder, начальный индекс и конечный индекс в качестве параметров. Если начальный индекс больше конечного, верните null (или эквивалент). Вычислите средний индекс как середину текущего диапазона. Создайте новый узел дерева со значением в среднем индексе. Рекурсивно создайте левое поддерево, используя левую половину текущего диапазона. Рекурсивно создайте правое поддерево, используя правую половину текущего диапазона. Верните корень вновь построенного сбалансированного BST. 😎 Решение: func balanceBST(root *TreeNode) *TreeNode {     if root == nil {         return nil     }     vineHead := &TreeNode{Right: root}     current := vineHead     for current.Right != nil {         if current.Right.Left != nil {             rightRotate(current, current.Right)         } else {             current = current.Right         }     }     nodeCount := 0     current = vineHead.Right     for current != nil {         nodeCount++         current = current.Right     }     m := int(math.Pow(2, math.Floor(math.Log2(float64(nodeCount+1))))) - 1     makeRotations(vineHead, nodeCount-m)     for m > 1 {         m /= 2         makeRotations(vineHead, m)     }     return vineHead.Right } func rightRotate(parent, node *TreeNode) {     tmp := node.Left     node.Left = tmp.Right     tmp.Right = node     parent.Right = tmp } func leftRotate(parent, node *TreeNode) {     tmp := node.Right     node.Right = tmp.Left     tmp.Left = node     parent.Right = tmp } func makeRotations(vineHead *TreeNode, count int) {     current := vineHead     for i := 0; i < count; i++ {         tmp := current.Right         leftRotate(current, tmp)         current = current.Right     } } Ставь 👍 и забирай 📚 Базу знаний
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