Golang | Leetcode Golang题解之第114题二叉树展开为链表

题目:

题解:

Go 复制代码
func flatten(root *TreeNode)  {
    curr := root
    for curr != nil {
        if curr.Left != nil {
            next := curr.Left
            predecessor := next
            for predecessor.Right != nil {
                predecessor = predecessor.Right
            }
            predecessor.Right = curr.Right
            curr.Left, curr.Right = nil, next
        }
        curr = curr.Right
    }
}
相关推荐
想吃火锅100517 小时前
【leetcode】14.最长公共前缀js
算法·leetcode·职场和发展
小林ixn18 小时前
LeetCode 206. 反转链表(迭代 + 递归详解)
算法·leetcode·链表
菜鸟‍20 小时前
LeetCode 1 27 和 704 || 两数之和 移除元素 二分查找
算法·leetcode·职场和发展
小小龙学IT20 小时前
Go 泛型深度解析:从设计哲学到工程实践
服务器·数据库·golang
退休倒计时21 小时前
【每日一题】LeetCode 142. 环形链表 II TypeScript
算法·leetcode·链表·typescript
张忠琳1 天前
【Go 1.26.4】(Part 2) Go 1.26.4 超深度分析 — Runtime GMP 调度器 (proc.go + runtime2.go)
开发语言·golang
sjsjs111 天前
力扣3558. 给边赋权值的方案数 I
算法·leetcode·职场和发展
花间相见1 天前
【LeetCode01】—— 无重复字符的最长子串:滑动窗口经典题详解
python·算法·leetcode
踏着七彩祥云的小丑1 天前
Go学习第5天:变量作用域 + 数组 + 指针
开发语言·学习·golang·go
言存1 天前
力扣热题283 移动零
数据结构·算法·leetcode