---
# System prepended metadata

title: \#94 Binary Tree Inorder Traversal
tags: [binary tree, leetcode, leetcode-easy]

---

# \#94 Binary Tree Inorder Traversal
## *遍歷二元樹(root.left->root->root.right)*
## Log
 - build 20210512 by syhuang

## 非遞迴版
 - 非遞迴版實作LVR
```javascript=
var inorderTraversal = function(root) {
    var r = [];
    var t = [];//暫存root.val
    var p = root;
    while(p || t.length>0){
        while(p){
            t.push(p);
            p = p.left;
        }
        p = t.pop();
        r.push(p.val);
        p = p.right;
    }
    return r;
};
```
## 初見
 - 遞迴實作LVR
```javascript=
var t = [];
var inorderTraversal = function(root) {
    if(!root) return [];
    return t.concat(
        inorderTraversal(root.left),
        root.val,
        inorderTraversal(root.right)
    );
};
```
## 備註
## 參考
 - [非遞迴版參考](https://leetcode.com/problems/binary-tree-inorder-traversal/discuss/31213/Iterative-solution-in-Java-simple-and-readable)
###### tags: `leetcode`, `leetcode-easy`, `binary tree`