Why below code is giving answer 0, it should be 4. please do the needful

private int SumLeafNode(Node node) {

	Stack<Integer> st = new Stack<Integer>();
	
	if (node == null) {
		return 0;
	}
	SumLeafNode(node.left);
	if (node.left == null && node.right == null) {
		st.push(node.data);
	}
	
	SumLeafNode(node.right);

	return st.size();

}

@vashisthdeepak928 wait buddy lemme check!

@vashisthdeepak928 why are you using stack here? You are using recursion so why using stack, is there any requirement of using extra data structure besides the call stack recursion is using because you have to just return sum thats all! And also make recursion stack and you will see why it is giving vague output to you.

I want to push all leaf node data into Stack.
I am unable to understand actual code of CB. You guys have putted the condition but in the last adding only left and right node data.

@vashisthdeepak928 Are your recursion concepts clear bro? Because the recursion in trees is pretty easy.

Those are the recursive calls made for left subtree and right subtree and this condition below is the positive base case which returns data of leaf node simple as that!

okay got it. Thank you