94. Binary Tree Inorder Traversal [JavaScript]

一、题目

  Given a binary tree, return the inorder traversal of its nodes’ values.

二、题目大意

  二叉树的中序遍历。

三、解题思路

  递归

四、代码实现

const inorderTraversal = root => {
  const ans = []
  help(root)
  return ans
  function help (root) {
    if (!root) {
      return
    }
    help(root.left)
    ans.push(root.val)
    help(root.right)
  }
}

  如果本文对您有帮助,欢迎关注微信公众号,为您推送更多大前端相关的内容, 欢迎留言讨论,ε=ε=ε=┏(゜ロ゜;)┛。

94. Binary Tree Inorder Traversal [JavaScript]_第1张图片

  您还可以在这些地方找到我:

  • 一个前端开发者的LeetCode刷题之旅
  • 掘金

你可能感兴趣的:(JavaScript,LeetCode)