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;

        

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings