求路径和,请问我这错在哪儿
public ArrayList<ArrayList<Integer>>
FindPath(TreeNode root,int target) {
ArrayList<ArrayList<Integer>> paths = new
ArrayList<ArrayList<Integer>>();
if(root == null)return paths;
ArrayList<Integer> path = new
ArrayList<Integer>();
int currentSum = 0;
FindPath(root,target,path,paths,currentSum);
return paths;
}
public void FindPath(TreeNode root,int
target,ArrayList<Integer>
path,ArrayList<ArrayList<Integer>> paths,int currentNum) {
currentNum += root.val;
path.add(root.val);
boolean isleaf = ((root.left ==
null)&&(root.right == null));
if((currentNum == target) && isleaf) {
paths.add(path);
}
if(root.left != null)
FindPath(root.left,target,path,paths,currentNum);
if(root.right != null)
FindPath(root.right,target,path,paths,currentNum);
path.remove(path.size() - 1);
}
结果显示为空,请问为什么
