559. Maximum Depth of N-ary Tree
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的更多相关文章
- 559. Maximum Depth of N-ary Tree - LeetCode
Question 559. Maximum Depth of N-ary Tree Solution 题目大意:N叉树求最大深度 思路:用递归做,树的深度 = 1 + 子树最大深度 Java实现: / ...
- (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&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 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(N-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 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS BFS 日期 题目地址:https://le ...
- [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) ...
随机推荐
- 洛谷P3327 约数个数和 结论+莫比乌斯反演
原题 就是让你求\(\sum\limits_{i=1}\sum\limits_{j=1}d(ij)\)(其中\(d(x)\)表示\(x\)的因数个数) 首先有引理(然而并没有证明): \(d(ij)= ...
- Linux系统网络编程中TCP通讯socket--send导致进程被关闭
https://blog.csdn.net/dsanmux/article/details/52083403 https://blog.csdn.net/u011425939/article/deta ...
- mkdir(): Permission denied
记录下,凡是遇到此类问题都是无权限导致. 根据不同场景,需要在不同的文件夹设置不同的权限. 例如,图片相关, 在php中,首先看下 配置php.ini的文件上传是否开启(file_uploads = ...
- kubernetes之flannel
kubernetes网络通信 容器间的通信 pod内的容器通信(lo) Pod之间的通信 pod IP <-----> pod IP Pod与Service之间的通信 podIP ...
- Apicloud学习第三天——获取云数据库的数据方法
apicloud学习30天中的对用进行注册和登录以及数据的获取的代码,在apicloud中有单独的api对用户的增删查改进行操作,这里写下增加和查询. 增加用户数据 var model=api.req ...
- Hadoop集群管理
1.简介 Hadoop是大数据通用处理平台,提供了分布式文件存储以及分布式离线并行计算,由于Hadoop的高拓展性,在使用Hadoop时通常以集群的方式运行,集群中的节点可达上千个,能够处理PB级的数 ...
- Asp.net core 3.0
序言 我的看法:如果你未来五到十年还打算靠 ASP.NET 吃饭,ASP.NET MVC 一定要学,写 WebForm 工作机会将变得很少,具备 MVC 技能才有本钱跟年轻小伙子们抢饭碗,很高比例的 ...
- 利用crontab定时提交svn遇到的几个问题
交待下背景...公司开发组只有技术经理有服务器和数据库权限,还只是开发环境的..因为工作安排和权限限制,测试同学上线的时候,需要本人帮开发组的部分同事review代码并把代码提交到trunk.一开始手 ...
- 如何在Eclipse中创建web项目并使用tomcat8 运行servlet开发简单的动态网页?
今天花了一天时间.因为用eclipse没多久,不是很熟悉使用,看的教程又是使用myeclipse的,但是eclipse相对没有myeclipse灵活,所以在网上找了很多资料,最后算是可以实现了.新手可 ...
- ansible初识
ansible: 运维自动化的工具, 基本功能, 基于ssh远程连接, 连接验证(ssh-keygen ssh-copy-id ip) 下载: 1. 安装epel源 wget -O /etc/yum ...