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
}
相关推荐
恋喵大鲤鱼24 分钟前
Golang 后台技术面试套题 1
面试·golang
Swift社区32 分钟前
Swift 实战:实现一个简化版的 Twitter(LeetCode 355)
leetcode·swift·twitter
火车叨位去19496 小时前
力扣top100(day04-05)--堆
算法·leetcode·职场和发展
Miraitowa_cheems7 小时前
LeetCode算法日记 - Day 11: 寻找峰值、山脉数组的峰顶索引
java·算法·leetcode
楼田莉子9 小时前
C++算法题目分享:二叉搜索树相关的习题
数据结构·c++·学习·算法·leetcode·面试
姜不吃葱11 小时前
【力扣热题100】双指针—— 接雨水
数据结构·算法·leetcode·力扣热题100
zzx_blog11 小时前
简单易懂的leetcode 100题-第三篇 移动0,颜色分类,数组中的第K个最大元素
leetcode·面试
路多辛11 小时前
Golang database/sql 包深度解析(二):连接池实现原理
数据库·sql·golang
kgduu11 小时前
go资料汇总
golang
qq_5139704412 小时前
力扣 hot100 Day76
算法·leetcode·职场和发展