dfs-104. Maximum Depth of Binary Tree
来源:互联网 发布:快手上的淘宝优惠群 编辑:程序博客网 时间:2024/06/09 18:03
题目:
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
对树左右递归,返回值较大的深度
因为电脑重装心情不好,我就长话短说了,下面是代码
class Solution {public: int maxDepth(TreeNode *root) { if (!root)return 0; int Left = 1; int Right = 1; if (root->left) Left = Left + maxDepth(root->left); if (root->right) Right = Right + maxDepth(root->right); return (Left > Right)? Left:right; }};
0 0
- DFS:104. Maximum Depth of Binary Tree
- 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] 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
- C# 基于iTextSharp封装的PDF操作类
- 分析system_call中断处理过程
- CVPR2016代码合集
- pwnable.kr writeup hash
- 链表相关面试题(一)
- dfs-104. Maximum Depth of Binary Tree
- android UI 五大布局
- SSH实现批量删除
- 产品经理的要学习的知识
- Effective C++ 读书笔记
- Android设计模式(二)- 续:WindowManager
- 【Coursera Machine Learning】 Week2 学习笔记
- 哈希(散列)表之开放定址法的C++类模板实现
- 论文查重 降重复度?