题解#DFS求解最大深度#
二叉树的最大深度
http://www.nowcoder.com/practice/8a2b2bf6c19b4f23a9bdb9b233eefa73
class Solution {
public:
/**
*
* @param root TreeNode类
* @return int整型
*/
int DFS(TreeNode* node){
if(node==NULL)
return 0;
int depth=1;
int left=DFS(node->left);
int right=DFS(node->right);
return left>right?depth+left:depth+right;
}
int maxDepth(TreeNode* root) {
// write code here
int depth=DFS(root);
return depth;
}
};