描述
给定一个二叉树的根节点root,返回它的 中序 遍历。
示例 1:
输入:root = [1,null,2,3]
输出:[1,3,2]
示例 2:
输入:root = []
输出:[]
题解
这道题的具体解法,可参看 力扣官方题解方法一
/*** Definition for a binary tree node.* function TreeNode(val, left, right) {* this.val = (val===undefined ? 0 : val)* this.left = (left===undefined ? null : left)* this.right = (right===undefined ? null : right)* }*//*** @param {TreeNode} root* @return {number[]}*/var inorderTraversal = function(root) {let list = []inorder(root, list)return list};const inorder = (root, list) => {if (!root) return nullinorder(root.left, list)list.push(root.val)inorder(root.right, list)return list}
