mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-11-01 03:23:42 +00:00
Update 34. 二叉树中和为某一值的路径.md
题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# 34. 二叉树中和为某一值的路径
|
# 34. 二叉树中和为某一值的路径
|
||||||
|
|
||||||
[NowCoder](https://www.nowcoder.com/practice/b736e784e3e34731af99065031301bca?tpId=13&tqId=11177&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
|
[Leetcode](https://leetcode.cn/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof/)
|
||||||
|
|
||||||
## 题目描述
|
## 题目描述
|
||||||
|
|
||||||
@@ -13,14 +13,15 @@
|
|||||||
## 解题思路
|
## 解题思路
|
||||||
|
|
||||||
```java
|
```java
|
||||||
private ArrayList<ArrayList<Integer>> ret = new ArrayList<>();
|
private List<List<Integer>> ret = new ArrayList<>();
|
||||||
|
|
||||||
public ArrayList<ArrayList<Integer>> FindPath(TreeNode root, int target) {
|
public List<List<Integer>> pathTarget(TreeNode root, int target) {
|
||||||
|
ret = new ArrayList<>();
|
||||||
backtracking(root, target, new ArrayList<>());
|
backtracking(root, target, new ArrayList<>());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void backtracking(TreeNode node, int target, ArrayList<Integer> path) {
|
private void backtracking(TreeNode node, int target, List<Integer> path) {
|
||||||
if (node == null)
|
if (node == null)
|
||||||
return;
|
return;
|
||||||
path.add(node.val);
|
path.add(node.val);
|
||||||
|
|||||||
Reference in New Issue
Block a user