number of nodes of trees

 int numNodes(TreeNode<int>* root){

    int ans=1;

    for(int i=0;i<root->children.size();i++){

        ans+=numNodes(root->children[i]);

    }

    return ans;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings