给定一个二叉树的根节点
root
,返回 它的 中序 遍历 。
输入:root = [1,null,2,3] 输出:[1,3,2]
/**
* 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) {
const res=[]
const inorder = (r) => {
if(!r){
return
}
inorder(r.left)
res.push(r.val)
inorder(r.right)
}
inorder(root)
return res
};