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
    }
}
相关推荐
小高Baby@6 小时前
Go语言中判断map 中是否包含某个key 的方法
golang
源代码•宸7 小时前
Leetcode—620. 有趣的电影&&Q3. 有趣的电影【简单】
数据库·后端·mysql·算法·leetcode·职场和发展
XFF不秃头10 小时前
力扣刷题笔记-旋转图像
c++·笔记·算法·leetcode
yaoh.wang13 小时前
力扣(LeetCode) 111: 二叉树的最小深度 - 解法思路
python·程序人生·算法·leetcode·面试·职场和发展·深度优先
仲夏月二十八13 小时前
关于golang中何时使用值对象和指针对象的描述
开发语言·后端·golang
天远数科14 小时前
Go语言金融风控:天远 全能小微企业报告组合接口的 AES 加密与异构 JSON 解析
大数据·golang·json
wodet14 小时前
golang实现的批量审核文本服务
微服务·golang
努力学算法的蒟蒻14 小时前
day42(12.23)——leetcode面试经典150
算法·leetcode·面试
鹿角片ljp15 小时前
力扣226.翻转二叉树-递归
数据结构·算法·leetcode
iAkuya15 小时前
(leetcode)力扣100 21搜索二维矩阵2(z型搜索)
linux·leetcode·矩阵