559. Maximum Depth of N-ary Tree

时间:2022-09-12 20:16:29

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. &lpar;N叉树 DFS 递归 BFS&rpar; leetcode 559&period; 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 ...

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

  3. &lbrack;LeetCode&amp&semi;Python&rsqb; Problem 559&period; 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 ...

  4. leetcode 559&period; 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&period; 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 ...

  6. 【LeetCode】559&period; Maximum Depth of N-ary Tree 解题报告(Python)

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

  7. &lbrack;LeetCode&rsqb; 559&period; Maximum Depth of N-ary Tree&lowbar;Easy tag&colon; DFS

    Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longe ...

  8. &lbrack;leetcode&rsqb; 559&period; Maximum Depth of N-ary Tree &lpar;easy&rpar;

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

  9. 559&period; Maximum Depth of N-ary Tree C&plus;&plus;N叉树的最大深度

    网址:https://leetcode.com/problems/maximum-depth-of-n-ary-tree/ 很简单的深度优先搜索 设定好递归返回的条件和值 /* // Definiti ...

随机推荐

  1. java中IO流小解

    下面这张图列出了java中一些处理流: java中根据操作对象的不同可以分为:字节流和字符流. 首先我们先表示一下什么叫节点流和处理流: 节点流:可以从或向一个特定的地方(节点)读写数据.如FileR ...

  2. NFA转DFA - json数字识别

    json的主页上,提供了number类型的符号识别过程,如下: 图片引用:http://www.json.org/json-zh.html 实际上这张图片表示的是一个状态机,只是状态没有标出来.因为这 ...

  3. Spring-MVC配置方法

    什么是spring-mvc 实现了mvc结构的spring模块,spring-mvc模块封装了web开发中的常用功能,简化了web过程. DispatcherServlet处理浏览器发来的请求 Han ...

  4. Oracle V&dollar;SESSION详解

    V$SESSION是APPS用户下面对于SYS.V_$SESSION 视图的同义词. 在本视图中,每一个连接到数据库实例中的session都拥有一条记录.包括用户session及后台进程如DBWR,L ...

  5. O-C相关-09-id 类型与应用

    09-id 类型与应用 1, 使用 NSObject 访问子类对象方法 代码在编辑的时候, Xcode 会实时检查语法情况. 如果调用某个对象的方法, 在声明中没有该方法的声明, 那么就会报错. 但是 ...

  6. banana pro 板子

    http://www.lemaker.org/cn/article-23-1.html

  7. ImageMagick简单记录

    一.安装 mac下的安装非常简单 brew search ImageMagick brew install xxx 安装后,可验证 magick logo: logo.gif identify log ...

  8. ElasticSearch(一)-- 简介

    ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elasticsearch是用Java开发的,并作为Apach ...

  9. OpenGL入门程序四:颜色模式

    1.OpenGL支持两种颜色模式: 1>RGBA颜色模式 ,用 glClearColor 指定清空屏幕后的颜色,即“空颜色” . 2>索引颜色模式,用 glClearIndex 指定清空屏 ...

  10. python接口自动化3-自动发帖(session)

    前言 上一篇模拟登录博客园,但这只是第一步,一般登录后,还会有其它的操作,如发帖,评论等,这时候如何保持会话呢? (敲黑板!!!由于博客园最近登录机制变了,登录全部走cookie登录) 一.sessi ...