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
}
相关推荐
Cx330❀1 小时前
【优选算法必刷100题】第038题(位运算):消失的两个数字
开发语言·c++·算法·leetcode·面试
漫随流水1 小时前
leetcode回溯算法(93.复原IP地址)
数据结构·算法·leetcode·回溯算法
艾莉丝努力练剑1 小时前
【优选算法必刷100题】第021~22题(二分查找算法):山脉数组的峰顶索引、寻找峰值
数据结构·c++·算法·leetcode·stl
Lips6114 小时前
2026.1.25力扣刷题笔记
笔记·算法·leetcode
源代码•宸4 小时前
Leetcode—746. 使用最小花费爬楼梯【简单】
后端·算法·leetcode·职场和发展·golang·记忆化搜索·动规
沉默-_-4 小时前
力扣hot100-子串(C++)
c++·学习·算法·leetcode·子串
POLITE35 小时前
Leetcode 437. 路径总和 III (Day 16)JavaScript
javascript·算法·leetcode
历程里程碑6 小时前
双指针2--盛水最多的容器
大数据·数据结构·算法·leetcode·elasticsearch·搜索引擎·散列表
June bug6 小时前
(#数组/链表操作)寻找两个正序数组的中位数
数据结构·python·算法·leetcode·面试·职场和发展·跳槽
TracyCoder1237 小时前
LeetCode Hot100(8/100)—— 438. 找到字符串中所有字母异位词
算法·leetcode