Fix the code of preorder_traversal_iii_compact

This commit is contained in:
krahets
2023-07-21 22:08:26 +08:00
parent 075c3abf88
commit bba62bbe75
11 changed files with 19 additions and 10 deletions

View File

@ -21,6 +21,7 @@ public class preorder_traversal_iii_compact {
if (root.val == 7) {
// 记录解
res.Add(new List<TreeNode>(path));
path.RemoveAt(path.Count - 1);
return;
}
preOrder(root.left);
@ -40,7 +41,7 @@ public class preorder_traversal_iii_compact {
res = new List<List<TreeNode>>();
preOrder(root);
Console.WriteLine("\n输出所有根节点到节点 7 的路径,路径中不包含值为 3 的节点");
Console.WriteLine("\n输出所有根节点到节点 7 的路径,路径中不包含值为 3 的节点,仅包含一个值为 7 的节点");
foreach (List<TreeNode> path in res) {
PrintUtil.PrintList(path.Select(p => p.val).ToList());
}