题解 | #反转链表#

实现二叉树先序,中序和后序遍历

http://www.nowcoder.com/practice/a9fec6c46a684ad5a3abd4e365a9d362

/*
 * 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 res = [[],[],[]];
    const dfs = (node) => {
        if(!node) return;
        res[0].push(node.val);
        dfs(node.left);
        res[1].push(node.val);
        dfs(node.right);
        res[2].push(node.val);
    }
    dfs(root);
    return res;
}
module.exports = {
    threeOrders : threeOrders
};
全部评论

相关推荐

如题
投递阿里巴巴集团等公司10个岗位 >
点赞 评论 收藏
分享
好在哪里了?我请问了?
_hengheng:很好啊,我看旁边同事都入职了都有工作
点赞 评论 收藏
分享
在开会的单身狗很有一套:学院本被想着这么快有面试,而且简历废话太多了 那些在校经历什么荣誉什么的企业不关心
点赞 评论 收藏
分享
评论
5
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务