Path Sum 2021-09-25 06:05

Problem Description

public boolean hasPathSum(TreeNode root, int targetSum) {
    if (root == null) {
        return false;
    }
    if (root.left == null && root.right == null) {
        return root.val == targetSum;
    }
    return hasPathSum(root.left, targetSum - root.val) || hasPathSum(root.right, targetSum - root.val);
}
Runtime Memory
0 ms 38.5 MB

henryxi leetcode list

EOF