注意:
1.preorderTraversal
只是充当函数入口,不然递归的时候无法正确返回数组
2.
function preorderTraversal( root ) {
function preOrder(root){
if(root == null) return;
res.push(root.val);
preOrder(root.left);
preOrder(root.right);
}
let res = [];
preOrder(root);
return res;
}
module.exports = {
preorderTraversal : preorderTraversal
};