JavaScript Node 模式

直接合在一个数组里面!

/*
 * function TreeNode(x) {
 *   this.val = x;
 *   this.left = null;
 *   this.right = null;
 * }
 */

/**
 *
 * @param root TreeNode类 the root of binary tree
 * @return int整型二维数组
 */
function threeOrders(root) {
  // write code here
    const ans = [[],[],[]]
    if(!root){
        return ans
    }
    const dfs = (root, ans) => {
        ans[0].push(root.val);
        root.left && dfs(root.left, ans);
        ans[1].push(root.val);
        root.right && dfs(root.right, ans);
         ans[2].push(root.val);
    };
    dfs(root, ans);
    return ans;
  
}
module.exports = {
  threeOrders: threeOrders,
};