int fun(Node *root)
{
static int sum = 0;
if(!root)
return 0;
if(root->right)
{
if(!root->right->left && !root->right->right)
{
sum+=root->right->data;
}
}
fun(root->left);
fun(root->right);
return sum;
}
int rightLeafSum(Node* root)
{
return fun(root);
}
void fun(Node *root, int *sum)
{
if(!root)
return;
if(root->right)
{
if(!root->right->left && !root->right->right)
{
*sum+=root->right->data;
}
}
fun(root->left,sum);
fun(root->right,sum);
}
int rightLeafSum(Node* root)
{
int sum=0;
fun(root,&sum);
return sum;
}