0
点赞
收藏
分享

微信扫一扫

LC-二叉树的中序遍历(JavaScript实现)

草原小黄河 2022-02-05 阅读 45
/*
 * @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


举报

相关推荐

0 条评论