mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
Fix the code of preorder_traversal_iii_compact
This commit is contained in:
@ -24,6 +24,7 @@ public class preorder_traversal_iii_compact {
|
||||
if (root.val == 7) {
|
||||
// 记录解
|
||||
res.add(new ArrayList<>(path));
|
||||
path.remove(path.size() - 1);
|
||||
return;
|
||||
}
|
||||
preOrder(root.left);
|
||||
@ -42,7 +43,7 @@ public class preorder_traversal_iii_compact {
|
||||
res = new ArrayList<>();
|
||||
preOrder(root);
|
||||
|
||||
System.out.println("\n输出所有根节点到节点 7 的路径,且路径中不包含值为 3 的节点");
|
||||
System.out.println("\n输出所有根节点到节点 7 的路径,路径中不包含值为 3 的节点,仅包含一个值为 7 的节点");
|
||||
for (List<TreeNode> path : res) {
|
||||
List<Integer> vals = new ArrayList<>();
|
||||
for (TreeNode node : path) {
|
||||
|
||||
Reference in New Issue
Block a user