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
    }
}
相关推荐
程序员酥皮蛋8 分钟前
hot 100 第三十题 30. 两两交换链表中的节点
数据结构·算法·leetcode·链表
踩坑记录15 分钟前
leetcode hot100 207. 课程表 检测有向图中是否存在环 medium Kahn 算法 入度表 BFS 图论
leetcode·宽度优先
Mr_health42 分钟前
leetcode:组合排列系列
算法·leetcode·职场和发展
YGGP1 小时前
【Golang】LeetCode 238. 除了自身以外数组的乘积
leetcode
进击的荆棘1 小时前
算法——二分查找
c++·算法·leetcode
识君啊1 小时前
Java 滑动窗口 - 附LeetCode经典题解
java·算法·leetcode·滑动窗口
烟花落o2 小时前
【数据结构系列02】轮转数组、返回倒数第k个节点
数据结构·算法·leetcode·刷题
追随者永远是胜利者2 小时前
(LeetCode-Hot100)3. 无重复字符的最长子串
java·算法·leetcode·职场和发展·go
Lenyiin2 小时前
《LeetCode 顺序刷题》11 -20
java·c++·python·算法·leetcode·lenyiin
期末考复习中,蓝桥杯都没时间学了12 小时前
力扣刷题19
算法·leetcode·职场和发展