题目链接:https://leetcode-cn.com/problems/binary-tree-inorder-traversal/
同样有递归法与非递归法
递归法:
/**
* 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 arr = [];
inorder(root,arr);
return arr;
};
function inorder(root,res){
if(root== null) return;
inorder(root.left,res);
res.push(root.val);
inorder(root.right,res);
}
非递归法:
/**
* Definition for a binary tree no