技术栈

Golang | Leetcode Golang题解之第114题二叉树展开为链表

__AtYou__2024-05-27 8:34

题目:

题解:

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
    }
}
上一篇:LeetCode算法题:42. 接雨水(Java)
下一篇:【论文复现】LSTM长短记忆网络
相关推荐
米粒1
8 小时前
力扣算法刷题 Day 27
算法·leetcode·职场和发展
Mr_Xuhhh
10 小时前
LeetCode hot 100(C++版本)(上)
c++·leetcode·哈希算法
人间打气筒(Ada)
10 小时前
go实战案例:如何通过 Service Meh 实现熔断和限流
java·开发语言·golang·web·istio·service mesh·熔断限流
穿条秋裤到处跑
11 小时前
每日一道leetcode(2026.03.31):字典序最小的生成字符串
算法·leetcode
weixin_44919041
12 小时前
defer和defer func执行区别
golang
呆萌很
13 小时前
【GO】指针练习题
golang
副露のmagic
14 小时前
数组章节 leetcode 思路&实现
算法·leetcode·职场和发展
Frostnova丶
15 小时前
LeetCode 3474. 字典序最小的生成字符串
算法·leetcode·职场和发展
AlenTech
15 小时前
136. 只出现一次的数字 - 力扣(LeetCode)
leetcode
重庆小透明
15 小时前
力扣刷题【3】相交链表
算法·leetcode·链表
热门推荐
012026年3月AI领域大事件:DeepSeek引领开源风暴02GitHub 镜像站点03Qwen3.5-Omni与Qwen3.6模型全面解析(含测评/案例/使用教程)04围棋-html版本05Claude Code + GLM4.7 避坑指南:解决 Unable to connect to Anthropic services06“wsl --install -d Ubuntu-22.04”下载慢,中国地区离线安装 Ubuntu 22.04 WSL方法(亲测2025年5月6日)07纯 HTML/CSS/JS 实现的高颜值登录页,还会眨眼睛!少女心爆棚!08UV安装并设置国内源09让 Trae IDE 智能体 “读懂”文档 Excel+PDF+DOCX :mcp-documents-reader 工具使用指南10AI 编程效率翻倍:Superpowers Skills 上手清单 + 完整指南