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
    }
}
相关推荐
Emilia486.1 小时前
【Leetcode&nowcode】代码强化练习(二叉树)
算法·leetcode·职场和发展
墨染点香1 小时前
LeetCode 刷题【135. 分发糖果】
算法·leetcode·职场和发展
im_AMBER2 小时前
Leetcode 41
笔记·学习·算法·leetcode
Excuse_lighttime3 小时前
排序数组(快速排序算法)
java·数据结构·算法·leetcode·eclipse·排序算法
前进的李工4 小时前
LeetCode hot100:560 和为k的子数组:快速统计法
python·算法·leetcode·前缀和·哈希表
在等晚安么5 小时前
力扣面试经典150题打卡
java·数据结构·算法·leetcode·面试·贪心算法
Tony Bai5 小时前
【Go模块构建与依赖管理】01 前世今生:从 GOPATH 的“混乱”到 Go Modules 的“秩序”
开发语言·后端·golang
gopyer5 小时前
Go语言2D游戏开发入门004:零基础打造射击游戏《太空大战》3
golang·go·游戏开发
py有趣6 小时前
LeetCode算法学习之移动0
学习·算法·leetcode