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 longest path from the root node down to the farthest leaf node.
For example, given a 3-ary
tree:
We should return its max depth, which is 3.
/*
// Definition for a Node.
class Node {
public:
int val;
vector<Node*> children; Node() {} Node(int _val, vector<Node*> _children) {
val = _val;
children = _children;
}
};
*/
class Solution {
public:
int maxDepth(Node* root) {
if (root == NULL) {
return ;
} int maxd = ;
int tmp = ;
for (auto child : root->children)
{
tmp = + maxDepth(child);
if (tmp > maxd) {
maxd = tmp;
}
} return maxd;
} // int maxDepth(Node* root) {
// if (root == nullptr) return 0;
// int depth = 0;
// for (auto child : root->children) depth = max(depth, maxDepth(child));
// return 1 + depth;
// }
};
LeetCode 559. Maximum Depth of N-ary Tree(N-Tree的深度)的更多相关文章
- (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_Easy tag: DFS
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)
原题链接 思路: 简单bfs class Solution { public: int maxDepth(Node *root) { int depth = 0; if (root == NULL) ...
- 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 ...
随机推荐
- Codeforces A. Password(KMP的nxt跳转表)
题目描述: Password time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- jmeter多个接口测试
针对接口文档,进行对应接口设计,多个接口设计用例需要使用事物控制器. 1.通过登录接口提取sign值 发送一个登录请求,然后通过正则表达式提取该sign值 正则表达式的使用,我稍后会在下一个博文中详细 ...
- 如何将 egg-validate 插件的错误提示,修改为中文?
方案一(需要找到所有的提示并对应成中文,不是一个好方案:例子地址:https://github.com/cag2050/egg_mysql_demo/blob/master/app/controlle ...
- LeetCode 491. Increasing Subsequences
原题链接在这里:https://leetcode.com/problems/increasing-subsequences/ 题目: Given an integer array, your task ...
- 【转】Fiddler抓包指南:结合Proxifier工具
本文转自:https://blog.csdn.net/china_jeffery/article/details/93000824 本文介绍如何使用Fiddler抓取HTTP和HTTPS协议的包,同时 ...
- java 中类初始化,构造方法,静态成员变量,静态块的加载顺序
1.编译和运行概念要搞清:编译即javac的过程,负责将.java文件compile成.class文件,主要是类型.格式检查与编译成字节码文件,而加载是指java *的过程,将.class文件加载到内 ...
- python 启动pydoc查看文档
启动pydoc查看文档 python3 -m pydoc -p 访问http://localhost:6789 或者查看官方文档:https://seleniumhq.github.io/seleni ...
- Internet地址结构
IP地址结构及分类寻址 IP地址 = <网络号> + <主机号> ------------IPv4(32bit)点分四组表示法: 192.168.31.1 ...
- 如何在Docker容器之间拷贝数据
[编者的话]在容器之间拷贝数据是Docker一个重要而且基本的功能.拷贝数据到其他容器是一个经常使用到的场景,如当服务器遇到不可预见的“灾难”(注:断电,宕机)时,起到备份数据的作用.本文作者详细介绍 ...
- list删除、集合遍历删除
public static void main(String[] args) { ArrayList<Integer> list = new ArrayList<>(); li ...