/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
// 计算以root为根节点的子树的最大深度
int depth(TreeNode* root)
{
if(root==NULL){
return 0;
}
int left=depth(root->left);
int right=depth(root->right);
return max(left,right)+1;
}
// 中序遍历以root为根节点的树,存入动态数组中
void InOrder(TreeNode *root,vector<int>& vec){
if(!root){
return;
}
InOrder(root->left, vec);
vec.push_back(root->val);
InOrder(root->right, vec);
}