当前位置: 首页 > news >正文

Golang | Leetcode Golang题解之第430题扁平化多级双向链表

题目:

题解:

func dfs(node *Node) (last *Node) {cur := nodefor cur != nil {next := cur.Next// 如果有子节点,那么首先处理子节点if cur.Child != nil {childLast := dfs(cur.Child)next = cur.Next// 将 node 与 child 相连cur.Next = cur.Childcur.Child.Prev = cur// 如果 next 不为空,就将 last 与 next 相连if next != nil {childLast.Next = nextnext.Prev = childLast}// 将 child 置为空cur.Child = nillast = childLast} else {last = cur}cur = next}return
}func flatten(root *Node) *Node {dfs(root)return root
}

http://www.mrgr.cn/news/33915.html

相关文章:

  • C++标准库双向链表 list 中的insert函数实现。
  • C++离线查询
  • Golang | Leetcode Golang题解之第429题N叉树的层序遍历
  • Codeforces Round 969 (Div. 1) C. Eri and Expanded Sets(线段树维护差分数组gcd+双指针+尺取)
  • git-repo系列教程(4) windows平台下安装git-repo客户端
  • Leetcode 每日一题:Diameter of Binary Tree
  • AI教你学Python 第18天 : 线性数据结构
  • 程序员如何保持与提升核心竞争力
  • Study Plan For Algorithms - Part35
  • 快速了解使用路由器
  • 证书学习(五)Java实现RSA、SM2证书颁发
  • 【学习笔记】手写 Tomcat 五
  • Python | Leetcode Python题解之第430题扁平化多级双向链表
  • YOLO航拍车辆和行人识别
  • 实战篇 | WSL迁移Linux系统到非系统盘(完整实操版)
  • 旋转机械故障数据集 全网首发
  • 自然语言处理的算法:从SVM到Attention
  • UIKit-Camera
  • 滚动轴承故障诊断、预测与分类综合数据集
  • C语言 | Leetcode C语言题解之第430题扁平化多级双向链表