mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-11 06:56:06 +00:00
Fix the code of preorder_traversal_iii_compact
This commit is contained in:
@@ -23,6 +23,7 @@ function preOrder(
|
||||
if (root.val === 7) {
|
||||
// 记录解
|
||||
res.push([...path]);
|
||||
path.pop();
|
||||
return;
|
||||
}
|
||||
preOrder(root.left, path, res);
|
||||
@@ -41,7 +42,7 @@ const path: TreeNode[] = [];
|
||||
const res: TreeNode[][] = [];
|
||||
preOrder(root, path, res);
|
||||
|
||||
console.log('\n输出所有根节点到节点 7 的路径,且路径中不包含值为 3 的节点');
|
||||
console.log('\n输出所有根节点到节点 7 的路径,路径中不包含值为 3 的节点,仅包含一个值为 7 的节点');
|
||||
res.forEach((path) => {
|
||||
console.log(path.map((node) => node.val));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user