题解 | #反转链表#
实现二叉树先序,中序和后序遍历
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
};