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
    }
}
相关推荐
cpp_25015 分钟前
P2639 [USACO09OCT] Bessie‘s Weight Problem G
数据结构·算法·动态规划·题解·洛谷·背包dp
菜鸟丁小真1 小时前
LeetCode hot100 -131.分割回文串
数据结构·算法·leetcode·知识点总结
Morwit2 小时前
【力扣hot100】 416. 分割等和子集
数据结构·c++·算法·leetcode·职场和发展
宵时待雨3 小时前
优选算法专题3:二分查找
数据结构·c++·算法·leetcode·职场和发展
@小柯555m3 小时前
算法(字母异位词分组)
java·开发语言·算法·leetcode
cpp_25013 小时前
P1877 [HAOI2012] 音量调节
数据结构·c++·算法·动态规划·题解·洛谷·背包dp
木子墨5163 小时前
LeetCode 热题 100 精讲 | 矩阵与图论进阶篇:矩阵置零 · 螺旋矩阵 · 旋转图像 · 搜索二维矩阵 II · 岛屿数量 · 腐烂的橘子
c++·算法·leetcode·矩阵·力扣·图论
米粒14 小时前
力扣算法刷题 Day 52
算法·leetcode·职场和发展
Tomhex4 小时前
Go泛型实战:类型参数化应用
golang
小雅痞4 小时前
[Java][Leetcode hard] 68. 文本左右对齐
java·开发语言·leetcode