[leetcode ]429. N-ary Tree Level Order Traversale (easy)
原题
思路:
bfs,每一层遍历一次加到一个vector,同时把该点的子元素加到queue中。
class Solution
{public:vector<vector<int>> levelOrder(Node *root){vector<vector<int>> res;if (root == NULL)return res;queue<Node *> q;q.push(root);while (!q.empty()){vector<int> v;int len = q.size();for (int i = 0; i < len; i++){Node *temp = q.front();q.pop();v.push_back(temp->val);for (auto &a : temp->children){q.push(a);}}res.push_back(v);}return res;}
};
转载于:https://www.cnblogs.com/ruoh3kou/p/9893438.html
[leetcode ]429. N-ary Tree Level Order Traversale (easy)相关推荐
- [Leetcode]@python 107. Binary Tree Level Order Traversal II
题目链接 https://leetcode.com/problems/binary-tree-level-order-traversal-ii/ 题目原文 Given a binary tree, r ...
- 429. N-ary Tree Level Order Traversal - LeetCode
Question 429. N-ary Tree Level Order Traversal Solution 题目大意: N叉树,返回每层的值,从上到下,从左到右 思路: 利用队列遍历这个N叉树 J ...
- 429. N-ary Tree Level Order Traversal**
429. N-ary Tree Level Order Traversal** https://leetcode.com/problems/n-ary-tree-level-order-travers ...
- LeetCode: 107. Binary Tree Level Order Traversal II
题目 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from l ...
- [LeetCode] Binary Tree Level Order Traversal 二叉树层次遍历(DFS | BFS)
目录: 1.Binary Tree Level Order Traversal - 二叉树层次遍历 BFS 2.Binary Tree Level Order Traversal II - 二叉树层次 ...
- LeetCode 107. Binary Tree Level Order Traversal II
LeetCode 107. Binary Tree Level Order Traversal II Solution1:我的答案 比102那道题多了一行代码... /*** Definition f ...
- 107. Binary Tree Level Order Traversal II
题目 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from l ...
- 102. Binary Tree Level Order Traversal
题目 Binary Tree Level Order Traversal 层次遍历二叉树 链接 Given a binary tree, return the level order traversa ...
- Binary Tree Level Order Traversal II 解题思路
思路: 与Binary Tree Level Order Traversal I 几乎一样.只是最后将结果存放在栈里,然后在栈里再传给向量即可. 再次总结思路: 两个queue,先把第一个放进q1,循 ...
最新文章
- value_counts()
- 阿里园区生态技术联盟启动大会
- 增量备份和差异备份的区别|什么是增量差异备份
- 前端常用效果(2)带效果的tab切换
- 每天一个linux命令cd,每天一个linux命令-cd
- php server 域名,php 关于如何获取域名或者IP地址的$_SERVER['']
- Java使用JDBC连接随意类型数据库(mysql oracle。。)
- 平衡二叉树(AVL树)-详解平衡调整
- 动态规划--Leetcode64.最小路径和
- uni-app中使用腾讯位置服务实现小程序地图选点功能
- JAVA通过SSL证书创建MS AD账户及设置密码
- HBuilderX是什么
- 565.数组嵌套(力扣leetcode) 博主可答疑该问题
- 最速下降法 理论证明
- C语言基础视频教程-欧阳坚-专题视频课程
- 从零开始Ubuntu16.04+ORBSLAM2+ROS实验实录(四):ORBSLAM评估工具EVO的使用
- 中M22春C、Java入门练习( 7-13 后天 )
- vue随笔之二类型判断一
- Thunderbolt3 方案介绍及应用案例介绍
- QFP、LQFP、TQFP、TEQFP、BGA等芯片封装技术
热门文章
- 不懂Python装饰器?教程双手奉上!
- 重磅开源!新型VOLO打破多项记录!
- 收藏 | 12 种 NumpyPandas 高效技巧
- 重磅!Yolo v4横空出世!刚刚开源!
- C++ Primer 第五版 第6章 6.3——函数返回类型和return语句阅读笔记
- GPU CUDA 杭州宣讲会
- hjimce算法类博文目录
- 基础知识(十四)服务器搭建
- 华为mate10pro测试软件,华为Mate10和华为Mate10Pro的区别在哪里?华为Mate10和华为Mate10Pro对比测评告诉你(附全文)...
- VS-001-概述-003-系统架构及业务流程--004-常见问题定位思路