//采用两层递归循环来解决问题

public class Solution {

public int sumOfPath = 0;
public int FindPath (TreeNode root, int sum) {
    // write code here
    if(root==null){
        return 0;
    }
    computePath(root,sum);
    return sumOfPath;
}

public void computePath(TreeNode root, int sum){
    computeFindPath(root,0,sum);
    if(root.left!=null){
        computePath(root.left,sum);
    }
    if(root.right!=null){
        computePath(root.right,sum);
    }
}

private void computeFindPath(TreeNode root, int sum,int target) {
    if(root==null){
        return;
    }
    sum+= root.val;
    if(sum==target){
        sumOfPath++;
    }
    computeFindPath(root.left,sum,target);
    computeFindPath(root.right,sum,target);
}

}