mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-11 06:56:06 +00:00
Fix the indentation of JS and TS code.
This commit is contained in:
@@ -9,25 +9,25 @@ const { printTree } = require('../modules/PrintUtil');
|
||||
|
||||
/* 前序遍历:例题三 */
|
||||
function preOrder(root, path, res) {
|
||||
// 剪枝
|
||||
if (root === null || root.val === 3) {
|
||||
return;
|
||||
}
|
||||
// 尝试
|
||||
path.push(root);
|
||||
if (root.val === 7) {
|
||||
// 记录解
|
||||
res.push([...path]);
|
||||
}
|
||||
preOrder(root.left, path, res);
|
||||
preOrder(root.right, path, res);
|
||||
// 回退
|
||||
path.pop();
|
||||
// 剪枝
|
||||
if (root === null || root.val === 3) {
|
||||
return;
|
||||
}
|
||||
// 尝试
|
||||
path.push(root);
|
||||
if (root.val === 7) {
|
||||
// 记录解
|
||||
res.push([...path]);
|
||||
}
|
||||
preOrder(root.left, path, res);
|
||||
preOrder(root.right, path, res);
|
||||
// 回退
|
||||
path.pop();
|
||||
}
|
||||
|
||||
// Driver Code
|
||||
const root = arrToTree([1, 7, 3, 4, 5, 6, 7]);
|
||||
console.log("\n初始化二叉树");
|
||||
console.log('\n初始化二叉树');
|
||||
printTree(root);
|
||||
|
||||
// 前序遍历
|
||||
@@ -35,7 +35,7 @@ const path = [];
|
||||
const res = [];
|
||||
preOrder(root, path, res);
|
||||
|
||||
console.log("\n输出所有根节点到节点 7 的路径,且路径中不包含值为 3 的节点");
|
||||
res.forEach(path => {
|
||||
console.log(path.map(node => node.val));
|
||||
console.log('\n输出所有根节点到节点 7 的路径,且路径中不包含值为 3 的节点');
|
||||
res.forEach((path) => {
|
||||
console.log(path.map((node) => node.val));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user