LeetCode题解之N-ary Tree Level Order Traversal
1、题目描述
2、问题分析
利用先进先出队列解决问题。
3、代码
vector<vector<int>> levelOrder(Node* root) {
vector<vector<int>> v;
if (root == NULL)
return v; queue<Node*> q;
q.push(root);
vector<int> v1; while (!q.empty()) {
int size = q.size();
for(int i = ; i < size; i++) {
Node *tmp = q.front();
q.pop();
v1.push_back(tmp->val);
for (auto it : tmp->children)
q.push(it);
}
v.push_back(v1);
v1.clear();
} return v;
}
LeetCode题解之N-ary Tree Level Order Traversal的更多相关文章
- 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 && Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal 题目链接 题目要求: Given a binary tree, return the level order traversal o ...
- LeetCode(26)-Binary Tree Level Order Traversal II
题目: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from ...
- [LeetCode&Python] Problem 107. Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- [LeetCode&Python] Problem 429. N-ary Tree Level Order Traversal
Given an n-ary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
- LeetCode(102) Binary Tree Level Order Traversal
题目 Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to rig ...
- Leetcode PHP题解--D125 107. Binary Tree Level Order Traversal II
val = $value; } * } */ class Solution { private $vals = []; /** * @param TreeNode $root * @return In ...
- 【leetcode❤python】102. Binary Tree Level Order Traversal
#-*- coding: UTF-8 -*-#广度优先遍历# Definition for a binary tree node.# class TreeNode(object):# def ...
- 【leetcode❤python】107. Binary Tree Level Order Traversal II
#-*- coding: UTF-8 -*- # Definition for a binary tree node.# class TreeNode(object):# def __init ...
- [LeetCode] Binary Tree Level Order Traversal II 二叉树层序遍历之二
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
随机推荐
- CentOS下使用crontab命令来定时执行任务
原文地址:http://www.centoscn.com/CentOS/help/2015/0424/5261.html crontab命令 是用来让使用者在固定时间或固定间隔执行程序之用,换句话说, ...
- StreamSets学习系列之StreamSets支持多种安装方式【Core Tarball、Cloudera Parcel 、Full Tarball 、Full RPM 、Docker Image和Source Code 】(图文详解)
不多说,直接上干货! Streamsets的官网 https://streamsets.com/ 得到 https://streamsets.com/opensource/ StreamSets支持多 ...
- JavaScript -- Select
-----053-Select.html----- <!DOCTYPE html> <html> <head> <meta http-equiv=" ...
- JavaScript -- Window-Blur
-----030-Window-Blur.html----- <!DOCTYPE html> <html> <head> <meta http-equiv=& ...
- 大整数相加 a+b 的c语言实现
终于来到我所期盼的高精度整数相加的题目了.这个题很经典,也算是一个很好的算法入门题吧. 如果是java的话,系统类库已经内置了BigInteger类,直接调用就可以很轻易地解决了.但是学习c的编写也是 ...
- 利用:before和:after伪类制作CSS3 圆形按钮 含demo
要求 必备知识 基本了解CSS语法,初步了解CSS3语法知识. 开发环境 Adobe Dreamweaver CS6 演示地址 演示地址 预览截图(抬抬你的鼠标就可以看到演示地址哦): 制作步骤: 一 ...
- php的explode()和implode()方法
php 中,字符串与数组互转 拆分字符串 到数组 explode() - -(其他语言中的 split) 将数组连接成字符串 implode() <?php $test = ' ...
- 基于SpringBoot+SSM实现的Dota2资料库智能管理平台
Dota2资料库智能管理平台的设计与实现 摘 要 当今社会,游戏产业蓬勃发展,如PC端的绝地求生.坦克世界.英雄联盟,再到移动端的王者荣耀.荒野行动的火爆.都离不开科学的游戏管理系统,游戏管理系 ...
- Python时间系统
Python的time和datetime模块提供了时间日期工具, python中的时间有4种表示方式: datetime obj time obj/tuple posix timestamp time ...
- Postman中使用post方式调用接口
选择body-row,输入data