alpha037/data-structures-and-algorithms

Nodedepth problem solution is wrong in this project

balamac opened this issue · 1 comments

NodeDepths problem in algoexpertsolution
ques: Need to find the depth of the tree.
below is the solution

int nodeDepth(TreeNode t, int ldepth, int rdepth) {

	if (t == null) {
		return 0;
	} else {

		ldepth = nodeDepth(t.left, ldepth, rdepth) + 1;

		rdepth = nodeDepth(t.right, ldepth, rdepth) + 1;

		if (ldepth > rdepth) {
			return ldepth;
		} else {
			return rdepth;
		}
	}
}

@balamac Hey, the question (original question on AlgoExpert) asks us to find the sum of all the node depths of the given binary tree.
Thanks!