package binarytrees;

/**
 * Given a binary tree and a sum, return true if the tree has a root-to-leaf
 * path such that adding up all the values along the path equals the given sum.
 * Return false if no such path can be found.
 */
public class TreeHasPathSum {
	public static boolean hasPathSum(TreeNode<Integer> root, int sum) {
		if (root == null) {
			return false;
		}

		Integer value = root.getValue();
		if (value == null) {
			throw new NullPointerException("You are an insane programmer.");
		}
		return hasPathSum(root.getLeft(), sum - value)
				|| hasPathSum(root.getRight(), sum - value)
				|| (sum - value == 0);
	}
}

@@ -620,16 +620,55 @@
 lue == 0
+ && !root.hasLeft() && !root.hasRight()
 );%0A%09%7D%0A%7D%0A

Fix hasPathSum.