/*
* @lc app=leetcode.cn id=94 lang=javascript
*
* [94] 二叉树的中序遍历
*/
// @lc code=start
/**
* 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 ans = [];
const inorder = root => {
if(root==null) return;
inorder(root.left)
ans.push(root.val)
inorder(root.right)
}
inorder(root);
return ans;
};
// @lc code=end
LC-二叉树的中序遍历(JavaScript实现)
于 2022-02-05 14:47:27 首次发布