We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7f8d973 commit 5217c9fCopy full SHA for 5217c9f
solution/0113.Path Sum II/Solution.java
@@ -0,0 +1,20 @@
1
+class Solution {
2
+ private List<List<Integer>> result = new ArrayList<>();
3
+ public List<List<Integer>> pathSum(TreeNode root, int sum) {
4
+ pathSum(root,new ArrayList<>(),sum);
5
+ return result;
6
+ }
7
+ private void pathSum(TreeNode root, List<Integer> list, int sum) {
8
+ if (root==null) return;
9
+ sum = sum - root.val;
10
+ list.add(root.val);
11
+ if (root.left==null && root.right==null){
12
+ ArrayList<Integer> integers = new ArrayList<>(list);
13
+ if (sum==0) result.add(integers);
14
+ } else {
15
+ pathSum(root.left,list,sum);
16
+ pathSum(root.right,list,sum);
17
18
+ list.remove(list.size()-1);
19
20
+}
0 commit comments