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

非常简单的题目,连edge case 都没有。思路就是:最大深度 = 孩子的最大深度 + 1

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

559. Maximum Depth of N-ary Tree的更多相关文章

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

随机推荐

  1. laravel windows安装

    第一步安装composer 下载地址:https://getcomposer.org/ 第二步:更改laravel下载地址 选项一.全局配置(推荐) $ composer config -g repo ...

  2. IPv4 forwarding is disabled. Networking will not work_问题解决

    构建Docker镜像时遇见的问题,特做以下记录: 1.编辑 vi /etc/sysctl.conf 2.添加 net.ipv4.ip_forward=1 3.重启network服务 systemctl ...

  3. C++回顾day03---<string字符串操作>

    一:string优点 相比于char*的字符串,C++标准程序库中的string类不必担心内存是否足够.字符串长度等等 而且作为一个类出现,他集成的操作函数足以完成我们大多数情况下的需要. 二:str ...

  4. 转载:在做datatable时候查询数据和条数只用一次sql就可以解决需求

    前言:最近用datatable处理数据比较多,所以在使用时候想提升性能 select * from t_hr_leave SELECT FOUND_ROWS() //返回查询记录的总数 select ...

  5. DirectX11--实现一个3D魔方(1)

    前言 可以说,魔方跟我的人生也有一定的联系. 在高中的学校接触到了魔方社,那时候的我虽然也能够还原魔方,可看到大神们总是可以非常快地还原,为此我也走上了学习高级公式CFOP的坑.当初学习的网站是在魔方 ...

  6. 一封来自恶魔的挑战邀请函,那些你见过或者没见过的C语言指针都在这里了

    前言 相信大多数的同学都是第一门能接触到语言是C/C++,其中的指针也是比较让人头疼的部分了,因为光是指针都能专门出一本叫<C和指针>的书籍,足见指针的强大.但如果不慎误用指针,这些指针很 ...

  7. Oracle DB Day01(SQL)

    --时间为什么不是现在呢? --设置时区和显示时间 ALTER DATABASE SET TIME_ZONE='+08:00' select to_char(current_timestamp at ...

  8. requests 获取token

    # encoding:utf-8 import reimport jsonimport randomfrom requests.sessions import Session class Regist ...

  9. DUMP 5 企业级电商项目

    [订单模块] 创建订单 商品信息  订单列表  订单详情 取消订单 订单列表  订单搜素  订单详情  订单发货 [创建订单]  购物车勾选商品 涉及 Cart Product  => 一个商品 ...

  10. 使用以太网通信方式刷新AB PLC固件

    本文详细介绍如何使用以太网通信方式刷新AB PLC固件 一.准备工作 1.  AB PLC控制器一台,本文以5069-L330ER为例,将其通电: 2.  5069-L330ER的IP已设置为172. ...