Skip to content

Latest commit

 

History

History
15 lines (14 loc) · 334 Bytes

0144-二叉树的前序遍历.md

File metadata and controls

15 lines (14 loc) · 334 Bytes
var preorderTraversal = function(root) {
  const res = []
  preorderTraversalNode(root, (v) => res.push(v))
  return res
};

var preorderTraversalNode = function(node, callback) {
  if (node !== null) {
    callback(node.val)
    preorderTraversalNode(node.left, callback)
    preorderTraversalNode(node.right, callback)
  }
}