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
    }
}
相关推荐
lvwangshu9 小时前
P5324 [BJOI2019] 删数 题解
线段树·题解·性质题
圣保罗的大教堂13 小时前
leetcode 3903. 最小稳定下标 I 简单
leetcode
FfHUCisI13 小时前
GMP 调度器:Go 并发的心脏是如何跳动的
开发语言·golang·php
sylviiiiiia14 小时前
Leetcode hot100 多数元素/相交链表/反转链表
算法·leetcode·链表
CoderYanger14 小时前
A.每日一题:3622. 判断整除性
java·程序人生·算法·leetcode·面试·职场和发展·蓝桥杯
rannn_11114 小时前
【力扣hot100】动态规划专题|70、118、198、279、322、139、300、152、416、32
算法·leetcode·动态规划
我不会起名字32214 小时前
一天一道算法题(26):栈的简单应用
java·数据结构·python·算法·leetcode·golang·
gsls20080814 小时前
告别 Vault 的复杂度:用 Go 标准库给 Windows 凭据管理器装上 MCP
windows·golang·mcp
a1879272183115 小时前
【算法】动态规划入门:从打家劫舍到状态设计的三堂课
算法·leetcode·动态规划·dp·回溯·暴力
名字还没想好☜16 小时前
Go 时间格式化为什么用 2006-01-02:time.Format/Parse 的参考时间、时区与解析踩坑
开发语言·后端·golang·go