diff --git a/problems/0112.路径总和.md b/problems/0112.路径总和.md index 41463ec1..2fdd7741 100644 --- a/problems/0112.路径总和.md +++ b/problems/0112.路径总和.md @@ -377,22 +377,22 @@ class solution { ```java class solution { - public list> pathsum(treenode root, int targetsum) { - list> res = new arraylist<>(); + public List> pathsum(TreeNode root, int targetsum) { + List> res = new ArrayList<>(); if (root == null) return res; // 非空判断 - - list path = new linkedlist<>(); + + List path = new LinkedList<>(); preorderdfs(root, targetsum, res, path); return res; } - public void preorderdfs(treenode root, int targetsum, list> res, list path) { + public void preorderdfs(TreeNode root, int targetsum, List> res, List path) { path.add(root.val); // 遇到了叶子节点 if (root.left == null && root.right == null) { // 找到了和为 targetsum 的路径 if (targetsum - root.val == 0) { - res.add(new arraylist<>(path)); + res.add(new ArrayList<>(path)); } return; // 如果和不为 targetsum,返回 }