Update 0112.路径总和.md

修复了 0113.路径总和-ii 中Java递归解法中的类名大小写问题。
This commit is contained in:
cy948
2022-05-06 14:43:58 +08:00
committed by GitHub
parent 8e070aeb48
commit cb6f015186

View File

@ -377,22 +377,22 @@ class solution {
```java
class solution {
public list<list<integer>> pathsum(treenode root, int targetsum) {
list<list<integer>> res = new arraylist<>();
public List<List<Integer>> pathsum(TreeNode root, int targetsum) {
List<List<Integer>> res = new ArrayList<>();
if (root == null) return res; // 非空判断
list<integer> path = new linkedlist<>();
List<Integer> path = new LinkedList<>();
preorderdfs(root, targetsum, res, path);
return res;
}
public void preorderdfs(treenode root, int targetsum, list<list<integer>> res, list<integer> path) {
public void preorderdfs(TreeNode root, int targetsum, List<List<Integer>> res, List<Integer> 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返回
}