mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-10 22:46:07 +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, res) {
|
||||
if (root === null) {
|
||||
return;
|
||||
}
|
||||
if (root.val === 7) {
|
||||
// 记录解
|
||||
res.push(root);
|
||||
}
|
||||
preOrder(root.left, res);
|
||||
preOrder(root.right, res);
|
||||
if (root === null) {
|
||||
return;
|
||||
}
|
||||
if (root.val === 7) {
|
||||
// 记录解
|
||||
res.push(root);
|
||||
}
|
||||
preOrder(root.left, res);
|
||||
preOrder(root.right, res);
|
||||
}
|
||||
|
||||
// Driver Code
|
||||
const root = arrToTree([1, 7, 3, 4, 5, 6, 7]);
|
||||
console.log("\n初始化二叉树");
|
||||
console.log('\n初始化二叉树');
|
||||
printTree(root);
|
||||
|
||||
// 前序遍历
|
||||
const res = [];
|
||||
preOrder(root, res);
|
||||
|
||||
console.log("\n输出所有值为 7 的节点");
|
||||
console.log(res.map(node => node.val));
|
||||
console.log('\n输出所有值为 7 的节点');
|
||||
console.log(res.map((node) => node.val));
|
||||
|
||||
Reference in New Issue
Block a user