网址:https://leetcode.com/problems/maximum-depth-of-n-ary-tree/

很简单的深度优先搜索

设定好递归返回的条件和值

/*
// 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)
return ;
int res = ;
for(Node* child : root->children)
res = max(res,maxDepth(child)+);
return res;
}
};

559. Maximum Depth of N-ary Tree C++N叉树的最大深度的更多相关文章

  1. 559. Maximum Depth of N-ary Tree - LeetCode

    Question 559. Maximum Depth of N-ary Tree Solution 题目大意:N叉树求最大深度 思路:用递归做,树的深度 = 1 + 子树最大深度 Java实现: / ...

  2. (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 ...

  3. 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 ...

  4. [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 ...

  5. 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 ...

  6. 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 ...

  7. 【LeetCode】559. Maximum Depth of N-ary Tree 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS BFS 日期 题目地址:https://le ...

  8. [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 ...

  9. [leetcode] 559. Maximum Depth of N-ary Tree (easy)

    原题链接 思路: 简单bfs class Solution { public: int maxDepth(Node *root) { int depth = 0; if (root == NULL) ...

  10. 559. Maximum Depth of N-ary Tree

    https://leetcode.com/problems/maximum-depth-of-n-ary-tree/description/ 非常简单的题目,连edge case 都没有.思路就是:最 ...

随机推荐

  1. 【Oracle】【问题】

    1. java.sql.SQLException: 对只转发结果集的无效操作: last 参考:https://www.cnblogs.com/gaoyuchuanIT/articles/411888 ...

  2. VR外包AR外包公司(虚拟现实外包公司)承接虚拟现实项目开发(企业、教育、游戏)

    VR外包AR外包公司(虚拟现实外包公司)承接虚拟现实项目开发(企业.教育.游戏) 可公对公签正规合同,开发票. 我们是北京的公司.专业团队,成员为专业 VR/AR 产品公司一线开发人员,有大型产品开发 ...

  3. _event_worldstate

    EventId 事件ID ID WorldStateUI.dbc第10列数字部分 StartValue 起始值 Entry 更新世界状态需要击杀生物或摧毁物体的entry,正数为生物,负数为物体 St ...

  4. 转 class和struct最本质的区别

    class和struct最本质的区别是class是引用类型,而struct是值类型,它们在内存中的分配情况有所区别. 什么是class? class(类)是面向对象编程的基本概念,是一种自定义数据结构 ...

  5. PL/SQL Developer登录出现——Using a filter for all users can lead to poor performance!

    用PL/SQL  Developer登录Oracle时提示:Using a filter for all users can lead to poor performance! 分析:与Oracle的 ...

  6. 使用JS语句,利用for循环的方法创建表格的两种方法

    首先去layui官网下载教程示例,在项目中加载layui.css,layui.js,JQuery.js 第一种: 将jsp语句写成字符串的形式,使用document.write()方式输出: 代码如下 ...

  7. 安装ik分词器以及版本和ES版本的兼容性

    一.查看自己ES的版本号与之对应的IK分词器版本 https://github.com/medcl/elasticsearch-analysis-ik/blob/master/README.md 二. ...

  8. zipkin启动报错(Caused by: java.lang.ClassNotFoundException: zipkin.Component)的解决方法

    使用ziplin依赖: <dependency> <groupId>org.springframework.cloud</groupId> <artifact ...

  9. go 单进程并发

    demo1 // This sample program demonstrates how to create goroutines and // how the scheduler behaves. ...

  10. R语言 让纵坐标的标签显示为横向

    参考自153分钟学习R语言 坐标y 上的数字如何水平放置?仍然是绘图参数问题: ?par # see  lasplot(0, 0, xaxt="n" , type="n& ...