标签:des style blog http color get
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.
递归基础,不解释。
class Solution { public: int getMax(TreeNode *root, int depth) { if(root == NULL) return depth; else return 1+max(getMax(root->left, depth), getMax(root->right, depth)); } int maxDepth(TreeNode *root) { return getMax(root, 0); } };
【LeetCode】 Maximum Depth of Binary Tree,布布扣,bubuko.com
【LeetCode】 Maximum Depth of Binary Tree
标签:des style blog http color get
原文地址:http://www.cnblogs.com/ganganloveu/p/3811083.html