Number of Leave Nodes

 int getLeafNodeCount(TreeNode<int>* root) {

    // Write your code here

    int ans=0;

    if (root==NULL){

        return 0;

    }

    if (root->children.size()==0){

        ans=1;

        

    }

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

        ans+=getLeafNodeCount(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