赞
踩
This is the address of the question.
The key to this question is to find the height of the tree.
Let's show you the code for this question.
If you don't know what the height of the tree is, you can check out my previous blog post.
- int maxDepth(struct TreeNode* root) {
- if (root == NULL)
- return 0;
- int leftHeight = maxDepth(root->left);
- int rightHeight = maxDepth(root->right);
-
- return leftHeight > rightHeight ? leftHeight + 1 : rightHeight + 1;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。