-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path24.java
More file actions
29 lines (26 loc) · 800 Bytes
/
24.java
File metadata and controls
29 lines (26 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.ArrayList;
/**
public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
*/
public class Solution {
//本质是一个深度优先遍历
ArrayList<ArrayList<Integer>> result=new ArrayList<ArrayList<Integer>>();
ArrayList<Integer> temp=new ArrayList<Integer>();
public ArrayList<ArrayList<Integer>> FindPath(TreeNode root,int target) {
if(root==null) return result;
temp.add(root.val);
target=target-root.val;
if(target==0 && root.left==null && root.right==null) result.add(new ArrayList(temp));
FindPath(root.left,target);
FindPath(root.right,target);
temp.remove(temp.size()-1);
return result;
}
}