Golang | Leetcode Golang题解之第429题N叉树的层序遍历

题目:

题解:

Go 复制代码
func levelOrder(root *Node) (ans [][]int) {
    if root == nil {
        return
    }
    q := []*Node{root}
    for q != nil {
        level := []int{}
        tmp := q
        q = nil
        for _, node := range tmp {
            level = append(level, node.Val)
            q = append(q, node.Children...)
        }
        ans = append(ans, level)
    }
    return
}
相关推荐
Swift社区1 天前
LeetCode 465 最优账单平衡
算法·leetcode·职场和发展
weixin_445054721 天前
力扣热题51
c++·python·算法·leetcode
smj2302_796826521 天前
解决leetcode第3801题合并有序列表的最小成本
数据结构·python·算法·leetcode
Thetimezipsby1 天前
Go(GoLang)语言基础、知识速查
开发语言·后端·golang
sin_hielo1 天前
leetcode 1975
数据结构·算法·leetcode
2501_941820491 天前
面向零信任安全与最小权限模型的互联网系统防护设计思路与多语言工程实践分享
开发语言·leetcode·rabbitmq
cpp_25011 天前
P1583 魔法照片
数据结构·c++·算法·题解·洛谷
2501_941805931 天前
一次从接口网关到异步消息驱动架构演化的互联网系统实践技术随笔分享录
leetcode·决策树·贪心算法
黛色正浓1 天前
leetCode-热题100-二叉树合集(JavaScript)
javascript·算法·leetcode
炽烈小老头1 天前
【每天学习一点算法 2026/01/05】打乱数组
学习·算法·leetcode