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
    }
}
相关推荐
Pniubi4 小时前
力扣283移动零(双指针法)
算法·leetcode·职场和发展
旖旎夜光14 小时前
LeetCode 315: 算右侧小于当前元素的个数(归并排序) —— 题解
c++·学习·算法·leetcode·排序算法
文丑颜不良啊15 小时前
LeetCode1401~1420题目解析
java·leetcode
Nuanyt15 小时前
LeetCode Hot 100 链表专题2 3 题 (Java)
java·笔记·算法·leetcode·链表
文丑颜不良啊15 小时前
LeetCode1341~1360题目解析
java·leetcode
紧跟先前的步伐15 小时前
Go AI Agent 实战 22|完善 Agent 执行循环:从工具调用到最终回答
人工智能·ai·golang
海绵宝宝转agent15 小时前
LeetCodehot100题解
java·笔记·学习·算法·leetcode·深度优先
后台模板学习17 小时前
Go Web开发中任务调度框架的源码解析与高可用实现方案
开发语言·后端·golang
FungLeo17 小时前
成为全栈·Go 后端篇·分类树与标签关系:目录变更为何需要协调
golang·go·gorm·数据库事务·分类树·成为全栈
Pniubi17 小时前
力扣543二叉树的直径(深度优先搜索法(递归))
算法·leetcode·职场和发展