[leetcode] 112. Path Sum 解题报告

根部到叶子节点路径之和为某值,递归

public boolean hasPathSum(TreeNode root, int sum) {
        if (root==null) return false;
        if (root.val==sum && root.left==null && root.right==null) return true;
        return hasPathSum(root.left,sum-root.val) || hasPathSum(root.right,sum-root.val);
    }
原文地址:https://www.cnblogs.com/pulusite/p/7762854.html