Count Leaves in Binary Tree

PHOTO EMBED

Fri Mar 03 2023 18:44:10 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

int countLeaves(Node* root)
{
    int c=0;
    queue<Node*> q;
    q.push(root);
    
    while(!q.empty())
    {
        Node* temp=q.front();
        q.pop();
        
        if(temp->left==NULL&&temp->right==NULL) c++;
        
        if(temp->left) q.push(temp->left);
        if(temp->right) q.push(temp->right);
    }
    return c;
  // Your code here
}
content_copyCOPY

https://practice.geeksforgeeks.org/problems/count-leaves-in-binary-tree/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article