[leetcode] 559. Maximum Depth of N-ary Tree (easy)
原题链接
思路:
简单bfs
class Solution
{
public:
int maxDepth(Node *root)
{
int depth = 0;
if (root == NULL)
return 0;
queue<Node *> q;
q.push(root);
while (q.size() > 0)
{
depth++;
int len = q.size();
for (int i = 0; i < len; i++)
{
vector<Node *> temp = q.front()->children;
q.pop();
for (Node *n : temp)
{
q.push(n);
}
}
}
return depth;
}
};
[leetcode] 559. Maximum Depth of N-ary Tree (easy)的更多相关文章
- (N叉树 DFS 递归 BFS) leetcode 559. Maximum Depth of N-ary Tree
Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longe ...
- LeetCode 559 Maximum Depth of N-ary Tree 解题报告
题目要求 Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the ...
- leetcode 559. Maximum Depth of N-ary Tree
Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longe ...
- LeetCode 559. Maximum Depth of N-ary Tree(N-Tree的深度)
Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longe ...
- [LeetCode] 559. Maximum Depth of N-ary Tree_Easy tag: DFS
Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longe ...
- 559. Maximum Depth of N-ary Tree - LeetCode
Question 559. Maximum Depth of N-ary Tree Solution 题目大意:N叉树求最大深度 思路:用递归做,树的深度 = 1 + 子树最大深度 Java实现: / ...
- 【LeetCode】559. Maximum Depth of N-ary Tree 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS BFS 日期 题目地址:https://le ...
- [LeetCode&Python] Problem 559. Maximum Depth of N-ary Tree
Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longe ...
- LeetCode 104. Maximum Depth of Binary Tree (二叉树的最大深度)
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
随机推荐
- Delphi中取得汉字的首字母(十分巧妙)
function Tdm.GetHzPy(const AHzStr: string): string;const ChinaCode: array[0..25, 0..1] of Integer = ...
- mysql数据库同步系统otter部署实践(中国与欧洲同步)
otter的介绍就不说了, 自己去看官网https://github.com/alibaba/otter/wiki 本系统中, 中国的服务器部署在阿里云上, 欧洲服务器部署在亚马逊上, 由于阿里云的网 ...
- Unity 入門 - 延遲解析
本文大纲: 小引 共享的范例代码 使用 Lazy<T> 使用自动工厂 注入自定义工厂 小引 当我们说「解析某个型别/组件」时,意思通常是呼叫某类别的建构函式,以建立其实例(instance ...
- C++实现半透明按钮控件(PNG,GDI+)
http://blog.csdn.net/witch_soya/article/details/6889904
- [java代码库]-简易计算器(第一种)
简易计算器(效果如图所示) 第一种方案:采用Javascript+html完成计算器,支持+-*/,结果显示不允许使用input输入域(可以考虑使用<span>) <html> ...
- python常用删除库的方法
本文记于初学py的时候,两年后补发. python常用库的安装方法一般有几种,比如: 1.编译过的exe包,直接无脑下一步就可以了. 2.pip install 库名,快速安装.自动匹配最新版本. 3 ...
- 程序代写, CS代写, 代码代写, CS编程代写, java代写, python代写, c++/c代写, R代写, 算法代写, web代写
互联网一线工程师程序代写 微信联系 当天完成 查看大牛简介特色: 学霸代写,按时交付,保证原创,7*24在线服务,可加急.用心代写/辅导/帮助客户CS作业. 客户反馈与评价 服务质量:保证honor ...
- 原创-使用pywinauto进行dotnet的winform程序控制(一)
pywinauto自动化控制win32的ui的程序,网上有好多的教程.但是操作dotnet写的winform教程,就少之又少.今天我就来分享我的pywinauto操作dotnet的winform的研究 ...
- Ubuntu --- 安装lnmp(php7.0)
1.安装nginx sudo apt-get install nginx # 安装 sudo vim /etc/nginx/sites-enabled/default # 修改配置文件 sudo ng ...
- HBase 学习之路(五)——HBase常用 Shell 命令
一.基本命令 打开Hbase Shell: # hbase shell 1.1 获取帮助 # 获取帮助 help # 获取命令的详细信息 help 'status' 1.2 查看服务器状态 statu ...