What's wrong in this the output is not coming right

public int sumleaf() {
int sum = 0;
return this.sumleaf(this.root, sum);
}
private int sumleaf(Node node, int sum) {
if(node == null) {
return sum;
}

		sumleaf(node.left, sum);
		sum = sum + node.data;
		sumleaf(node.right, sum);
		return sum;	
	}

In this question, you are asked to print the sum of all the leaf nodes. So while calculating the sum, we need to check if the present node is a leaf node or not. A leaf node has both left and right child as null. So the present node will contribute to the ans if and only if both of it’s children are leaf nodes. You need to check these conditions. Please watch the explanation video once again to understand the algorithm being used.

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.