Binary tree replace sum

sir ,I do understand that you wrote a condition for leaf nodes.
but why do we write a condition for nullptr nodes at the first??
if(root==nullptr)
return 0;
since we have only either a leaf node or regular nodes with children?
with all respect

Hey @mzk1994

You will call recursion From leaf nodes as well which will go to null and from there we return 0

Do a dry run and u will understand

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.