技术栈

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长短记忆网络
相关推荐
洛水水
2 小时前
【力扣100题】46.单词拆分
算法·leetcode·职场和发展
Wy_编程
3 小时前
Go语言中的指针
开发语言·后端·golang
lolo大魔王
4 小时前
Go语言数据库操作之GORM框架从入门到生产实战(完整版)
开发语言·数据库·golang
alphaTao
4 小时前
LeetCode 每日一题 2026/5/11-2026/5/17
算法·leetcode
洛水水
4 小时前
【力扣100题】45.零钱兑换
算法·leetcode·职场和发展
GDAL
5 小时前
Go mod tidy 完整教程:从入门到精通
golang·tidy
YL20040426
5 小时前
041二叉树的层序遍历
数据结构·leetcode·bfs
lolo大魔王
5 小时前
Go 语言 Web 框架 Gin 入门详解
前端·golang·gin
洛水水
6 小时前
【力扣100题】47.最长递增子序列
算法·leetcode·职场和发展
_日拱一卒
7 小时前
LeetCode:199二叉树的右视图
算法·leetcode·职场和发展
热门推荐
01GitHub 镜像站点02Codex 接入 DeepSeek API 完整配置文档03【AI】2026 年具身智能模型和世界模型总结04CC-Switch & Claude 基于 Linux 服务器安装使用指南05人工智能最新动态 AI 日报 · 2026年5月10日06AI科技热点日报 | 2026年5月11日07Gemini大升级、AI眼镜首发、Android XR亮相,13天后见分晓08零基础教你claude code 接入 deepseek V409codex app每次打开重连5次Reconnecting问题解决10Cursor 接入 DeepSeek‑V4‑Pro 完整指南(2026 实测)