Height of a tree
int getHeight(TreeNode<int>* root) {
// Write your code here
int ans=1;
int max=1;
for(int i=0;i<root->children.size();i++){
//max=0;
ans+=getHeight(root->children[i]);
if (max<ans){
max=ans;
}
ans=1;
}
return max;
}
int getHeight(TreeNode<int>* root) {
// Write your code here
int ans=1;
int max=1;
for(int i=0;i<root->children.size();i++){
//max=0;
ans+=getHeight(root->children[i]);
if (max<ans){
max=ans;
}
ans=1;
}
return max;
}
Comments
Post a Comment