三种 js & ts 树遍历生成器 All In One
three js tree traversal generator / three ts tree traversal generator
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2022-10-10
* @modified
*
* @description树 & 遍历
* @difficulty Easy
* @ime_complexity O(n)
* @space_complexity O(n)
* @augments
* @example
* @link https://leetcode.cn/leetbook/read/data-structure-binary-tree/xe17x7/
* @solutions
*
* @best_solutions
*
*/
// export {};
const log = console.log;
// Definition for a binary tree node.
class TreeNode {
val: number;
left: TreeNode | null;
right: TreeNode | null;
constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
this.val = (val === undefined ? 0 : val);
this.left = (left === undefined ? null : left);
this.right = (right === undefined ? null : right);
}
}
树遍历
前序遍历
/先序遍历
/ preorder traversal
中序遍历
/ inorder traversal
后序遍历
/ postorder traversal
preorder traversal tree generator
inorder traversal tree generator
postorder traversal tree generator
LeetCode
树的遍历
https://leetcode.cn/leetbook/read/data-structure-binary-tree/xe17x7/
二叉树遍历
https://leetcode.com/problems/binary-tree-preorder-traversal/
https://leetcode.cn/problems/binary-tree-preorder-traversal/
https://leetcode.com/problems/binary-tree-inorder-traversal/
https://leetcode.cn/problems/binary-tree-inorder-traversal/
https://leetcode.com/problems/binary-tree-postorder-traversal/
https://leetcode.cn/problems/binary-tree-postorder-traversal/