发布时间:2023-08-12 15:30
var preorderTraversal = function(root) {
const res = [];
const stack = [];
if(root) stack.push(root);
while(stack.length) {
const n = stack.pop()
res.push(n.val)
if(n.right) stack.push(n.right)
if(n.left) stack.push(n.left)
}