[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 ...
随机推荐
- Python 2, Python 3, Stretch & Buster
Python 2.7的终止支持时间为2020年,现在已经是2015年了,然而Debian中仍然有大量软件包是基于Python 2的实现.Debian的维护者开始认真讨论淘汰Python 2.开发者Pa ...
- Ansible的安装与使用初探
一.环境准备 网络配置 管理端:192.168.237.201 受控端:192.168.237.202.192.168.237.203(一共2台) 硬件信息 CPU:1核 内存:512MB 磁盘:10 ...
- U盘免疫
界面如下: 关键部分代码如下: void CImmunityUDlg::OnBnClickedButtonOk() { // TODO: 在此添加控件通知处理程序代码 TCHAR szPath[MAX ...
- 事务 ( 进程 ID 60) 与另一个进程被死锁在锁资源上,并且已被选作死锁牺牲品
Select * FROM [TableName] With(NoLock) .....
- [2017.02.13] linux平台下统计C++项目文件个数和代码行数
#输出排序后文件名 file='find . -name "*.[ch]" | sort' #统计文件个数 filecnt='find . -name "*.[ch]&q ...
- Linux字体显示不同颜色
功能介绍哦:让echo输出字符串显示不同颜色 一.字体颜色(范围:30-37) echo -e "\033[30m oldboy trainning \033[0m" 黑色字(黑色 ...
- Java Collection秋招复习
抽象类和接口的区别 我们先来看一下抽象类 * @auther draymonder */ public abstract class AbstractClassTest { private int T ...
- linux 环境 安装jdk tomcat mysql git
1.安装JDK 1.官方下载jdk,linux版本的rpm包 2.安装rz sz ----------编译安装 //安装 cd /tmp wget http://www.ohse.de/uwe/rel ...
- 洛谷 题解 UVA658 【这不是bug,而是特性 It's not a Bug, it's a Feature!】
[题意] 补丁在修正\(BUG\)时,有时也会引入新的\(BUG\),假定有\(n(n<=20)\)个潜在\(BUG\),和\(m(m<=100)\)个补丁,每个补丁用两个长度为\(n\) ...
- 【Dubbo】Dubbo+ZK基础入门以及简单demo
参考文档: 官方文档:http://dubbo.io/ duboo中文:https://dubbo.gitbooks.io/dubbo-user-book/content/preface/backgr ...