import java.util.*;


public class Solution {

    int res = 0;
    public int FindPath (TreeNode root, int sum) {
        // write code here
        if(root == null) return 0;
        // 计算根节点的路径
        dfs(root,sum);

        // 遍历树,每个节点都进行dfs计算路径
        FindPath(root.left, sum);
        FindPath(root.right, sum);

        return res;
    }

    public void dfs(TreeNode root, int sum){
        if(root == null){
            return;
        }
        if(sum - root.val == 0){
            res++;
        }
        dfs(root.left, sum - root.val);
        dfs(root.right, sum - root.val);
    }
}