Tree:给定二叉树与一个定值,判断从根节点到叶子节点是否存在一
2016-05-18 本文已影响365人
敲一手烂代码
public static boolean hasPathSum(BinTreeNode root, int sum) {
if(root == null) return false;
if(root.left == null && root.right == null && sum - root.value == 0) return true;
return hasPathSum(root.left, sum - root.value) || hasPathSum(root.right, sum - root.value);
}