и посмотреть медиа
Golang | LeetCode
и посмотреть медиа
LeetCode tasks in Golang. Solutions with code and explanations.
LeetCode tasks in Golang. Solutions with code and explanations.
AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.
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.
Задача: 1305. All Elements in Two Binary Search Trees Сложность: medium Даны два бинарных дерева поиска root1 и root2. Вернуть список, содержащий все целые числа из обоих деревьев, отсортированные в порядке возрастания. Пример: Input: root1 = [2,1,4], root2 = [1,0,3] Output: [0,1,1,2,3,4] 👨💻 Алгоритм: 1⃣Выполните итеративный обход в порядке возрастания обоих деревьев параллельно. 2⃣На каждом шаге добавляйте наименьшее доступное значение в выходной список. 3⃣Верните выходной список. 😎 Решение: package main type TreeNode struct { Val int Left *TreeNode Right *TreeNode } func getAllElements(root1 *TreeNode, root2 *TreeNode) []int { stack1, stack2 := []*TreeNode{}, []*TreeNode{} output := []int{} for root1 != nil || root2 != nil || len(stack1) > 0 || len(stack2) > 0 { for root1 != nil { stack1 = append(stack1, root1) root1 = root1.Left } for root2 != nil { stack2 = append(stack2, root2) root2 = root2.Left } if len(stack2) == 0 || (len(stack1) > 0 && stack1[len(stack1)-1].Val
Открыть канал и посмотреть медиаOnly registered users can share their opinion.
Be the first to share your impression of this resource!