public static boolean hasPathSum(Node node, int sum) { // return true if we run out of tree and sum==0 if (node == null) { return(sum == 0); } else { // otherwise check both subtrees int subSum = sum - node.data; System.out.println("subsum testting = "+subSum); return(hasPathSum(node.left, subSum) || hasPathSum(node.right, subSum)); } } }
Home » Binary Trees(We Are Computer Tree & NOT Free !) » Root to Leaf Sum