94. 二叉树的中序遍历
https://leetcode-cn.com/problems/binary-tree-inorder-traversal/
[x] iteration
[x] recursion
[ ] morris
iteration
var inorderTraversal = function(root) {let stack = [];let res = [];while(root !== null || stack.length){while(root !== null){stack.push(root);root = root.left;}root = stack.pop();res.push(root.val);root = root.right;}return res;}
- recursion
var inorderTraversal = function(root) {let res = [];let dfs = (root) =>{if (root == null)return;dfs(root.left);res.push(root.val);dfs(root.right);}dfs(root);return res;};
