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
    }
}
相关推荐
We་ct14 分钟前
LeetCode 300. 最长递增子序列:两种解法从入门到优化
开发语言·前端·javascript·算法·leetcode·typescript
迷茫运维路22 分钟前
云枢运维管理系统
运维·golang·kubernetes·gin·casbin
jieyucx43 分钟前
Go 语言运算符与控制台输入输出详解
开发语言·后端·golang
始三角龙1 小时前
LeetCode hoot 100 -- 找到字符串中的所有字母异位词
算法·leetcode·职场和发展
abant21 小时前
leetcode 45 跳跃问题2 很难的贪心
算法·leetcode·职场和发展
水木流年追梦3 小时前
CodeTop Top 100 热门题目(按题型分类)
算法·leetcode
Tisfy3 小时前
LeetCode 1722.执行交换操作后的最小汉明距离:连通图
算法·leetcode·dfs·题解·深度优先搜索·连通图
样例过了就是过了3 小时前
LeetCode热题100 杨辉三角
c++·算法·leetcode·动态规划
eggrall3 小时前
Leetcode 最大连续 1 的个数 III(medium)
算法·leetcode·职场和发展
Pentane.3 小时前
【力扣hot100】【Leetcode 54】螺旋矩阵|边界控制 算法笔记及打卡(19/100)
算法·leetcode·矩阵