# 104. Maximum Depth of Binary Tree

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.

dfs瞬间解决。

/**
* 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) {
int depth=0;
if (root)
depth=testMaxDepth(root->left,root->right);
else
return 0;
return depth;
}
int testMaxDepth(TreeNode* left,TreeNode* right)
{
int depth=1;
if (left&&right)
depth+=max(testMaxDepth(left->left,left->right),testMaxDepth(right->left,right->right));
else if (left) depth+=testMaxDepth(left->left,left->right);
else if (right) depth+=testMaxDepth(right->left,right->right);
return depth;
}
};

#### leetcode 104 Maximum Depth of Binary Tree二叉树求深度

2015-05-13 22:16:12

#### 104. Maximum Depth of Binary Tree [easy] (Python)

2016-05-07 13:21:08

#### 104. Maximum Depth of Binary Tree的C++解法

2017-03-30 13:31:29

#### Maximum Depth of Binary Tree -- LeetCode

2014-02-22 03:34:51

#### LeetCode104——Maximum Depth of Binary Tree

2015-02-05 15:29:44

#### 【LeetCode-面试算法经典-Java实现】【104-Maximum Depth of Binary Tree（二叉树的最大深度）】

2015-08-08 06:43:32

#### 104. Maximum Depth of Binary Tree(C语言）

2017-05-03 15:00:29

#### leetcode 104.Maximum Depth of Binary Tree-树的深度|递归

2015-10-04 22:19:28

#### LeetCode 104. Maximum Depth of Binary Tree C语言

2016-04-24 20:05:58

#### LeetCode：104_Maximum Depth of Binary Tree | 二叉树的最大深度 | 深度优先与广度优先深入理解

2016-08-07 20:29:26