int countLeaves(Node* root)
{
if(!root)
return 0;
if(root->left==NULL and root->right==NULL)
{
return 1;
}
return (countLeaves(root->left)+countLeaves(root->right));
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter