DFS:104. Maximum Depth of Binary Tree
来源:互联网 发布:php 获得父类的属性 编辑:程序博客网 时间:2024/06/18 11:46
最大深度,典型的dfs。差点又想加一个if(root->left == NULL && root->right == NULL),没必要。代码很简单:
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int maxDepth(TreeNode* root) { if(root == NULL ) return 0; else return max(maxDepth(root->left), maxDepth(root->right)) + 1; }};
阅读全文
0 0
- DFS:104. Maximum Depth of Binary Tree
- 【LeetCode】104. Maximum Depth of Binary Tree(DFS|BFS)
- LeetCode oj 104. Maximum Depth of Binary Tree(DFS||BFS)
- dfs-104. Maximum Depth of Binary Tree
- [DFS] leetcode 104. Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree(DFS)
- [LeetCode]104.Maximum Depth of Binary Tree
- 104.Maximum Depth of Binary Tree
- 【LeetCode】104.Maximum Depth of Binary Tree
- [Leetcode] 104. Maximum Depth of Binary Tree
- LeetCode --- 104. Maximum Depth of Binary Tree
- LeetCode 104. Maximum Depth of Binary Tree
- 104.Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 104.Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- leetCode 104. Maximum Depth of Binary Tree
- mac下Yii2如何安装advanced,mac下yii2 advanced安装教程
- C#之工大租车系统
- 文章标题
- 初“拾”C++
- 图
- DFS:104. Maximum Depth of Binary Tree
- 数据仓库
- python----去重
- 小学数学题 洛谷p2921
- ORM简介
- python基础知识1
- linux学习笔记(1)-基础命令
- 实验一:Linux操作系统的软件安装
- 30:字符环