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) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int left,right;
if(root==NULL)
return 0;
return (left=maxDepth(root->left))>(right=maxDepth(root->right))?left+1:right+1;
}
};
求二叉树的高