Leetcode559.Maximum Depth of N-ary TreeN叉树的最大深度
给定一个 N 叉树,找到其最大深度。
最大深度是指从根节点到最远叶子节点的最长路径上的节点总数。
说明:
- 树的深度不会超过 1000。
- 树的节点总不会超过 5000。
class Solution {
public:
int maxDepth(Node* root) {
if(root == NULL)
return 0;
int cnt = 0;
queue<Node*> q;
q.push(root);
while(!q.empty())
{
int s = q.size();
cnt++;
while(s--)
{
Node* node = q.front();
q.pop();
for(int i = 0; i < node ->children.size(); i++)
{
if(node ->children[i] != NULL)
{
q.push(node ->children[i]);
}
}
}
}
return cnt;
}
};
Leetcode559.Maximum Depth of N-ary TreeN叉树的最大深度的更多相关文章
- [LeetCode] Maximum Depth of N-ary Tree N叉树的最大深度
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 ...
- 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 ...
- LeetCode559. Maximum Depth of N-ary Tree
第一次写出了具有迭代和递归的函数,还是有点收获的,虽然题目比较简答 当要对某些对象重复使用时,考虑循环,也就是迭代 当函数可以简化一个重复的操作时,考虑递归,而且就当下一次使用这和函数的结果已经有啦, ...
- 【easy】104. Maximum Depth of Binary Tree 求二叉树的最大深度
求二叉树的最大深度 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; ...
- (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之深度优先搜索(DFS)专题-559. N叉树的最大深度(Maximum Depth of N-ary Tree)
Leetcode之深度优先搜索(DFS)专题-559. N叉树的最大深度(Maximum Depth of N-ary Tree) 深度优先搜索的解题详细介绍,点击 给定一个 N 叉树,找到其最大深度 ...
- C#LeetCode刷题之#559-N叉树的最大深度(Maximum Depth of N-ary Tree)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4088 访问. 给定一个 N 叉树,找到其最大深度. 最大深度是指 ...
- C#LeetCode刷题之#104-二叉树的最大深度(Maximum Depth of Binary Tree)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4072 访问. 给定一个二叉树,找出其最大深度. 二叉树的深度为根 ...
随机推荐
- Java学习之程序运行机制
Java的运行机制是:先编译,后解释. 典型的编译型编程语言是:C和C++. eg:用c语言编写的*.c文件编译生成*.h文件,通过链接将*.h文件链接成*.exe文件,然后就可以运行,编译型的高级语 ...
- 第三周课堂笔记1thand2thand3th
元组 元组是以逗号隔开的 元组有索引有切片,元组是小括号和中括号的集合, 元组中的东西不可修改(小括号内的东西不可被修改,但是小括号里的列表和字典可以被修改) 2. 由内存地址来分 可变数据类 ...
- 2019-8-31-C#-如何给-ValueTuple-返回值添加注释
title author date CreateTime categories C# 如何给 ValueTuple 返回值添加注释 lindexi 2019-08-31 16:55:58 +0800 ...
- new linux setup, yum command
7 yum list 9 cd /etc/yum.repos.d/ 55 history | grep yum 56 yum -y list screen* 57 yum -y instal ...
- JavaScript特效源码(5、背景特效)
1.数字时钟 背景时钟[好大的钟][推荐][共1步] ====1.以下是这个效果的全部代码.[最好从一个空页面开始] <html> <head> <TITLE>背景 ...
- 利用HttpWebRequest模拟提交图片
利用HttpWebRequest模拟提交图片 最近在做排量post工具, 以前做的都是提交文字 这次需要post图片过去,弄了半天终于弄好了: /// <summary> /// Post ...
- Android开发 GradientDrawable详解
前言 GradientDrawable类似与Xml布局里的shape,常用在一些自己封装的对话框控件的背景或者其他View中,优势是不需要你在带着xml布局文件一起封包.. 画线 GradientDr ...
- 在双重for循环内部使用async异步请求axios中遇到的问题
在methods中的方法 async getPro () { let _this = this let newArr = [] await axios.get(`api/v1/dailyProTbms ...
- Java虚拟机笔记
Java内存区域划分 1.程序计数器 线程私有,当前线程执行的行号指示器,指向当前线程执行的虚拟机字节码地址,线程的恢复,跳转等都需要用到它 2.Java虚拟机栈 线程私有,虚拟机栈描述的是Java内 ...
- 第九章 Odoo 12开发之外部 API - 集成第三方系统
Odoo 服务器端带有外部 API,可供网页客户端和其它客户端应用使用.本文中我们将学习如何在我们的客户端程序中使用 Odoo 的外部 API.为避免引入大家所不熟悉的编程语言,此处我们将使用基于 P ...