### 94. Binary Tree Inorder Traversal

题目:
<https://leetcode.com/problems/binary-tree-inorder-traversal/>


难度:

Medium


递归版本1⃣️：自己瞬秒的




```python
class Solution(object):
    def inorderTraversal(self, root):
        """
        :type root: TreeNode
        :rtype: List[int]
        """
        res = []
        if not root:
            return res
        if root.left: 
            res.extend(self.inorderTraversal(root.left))
        res.append(root.val)
        if root.right:
            res.extend(self.inorderTraversal(root.right))
        return res
```

递归版本2⃣️：
```python
class Solution(object):
    def inorderTraversal(self, root):
        """
        :type root: TreeNode
        :rtype: List[int]
        """
        self.lst = []
        self.DFS(root)
        return self.lst

    
    def DFS(self,root):
        if root == None:
            return
        if root.left:
            self.DFS(root.left)
        self.lst.append(root.val)
        if root.right:
            self.DFS(root.right)
                
```

非递归用stack，我听谁讲过 😓

// to be done


via wikipedia


递归：

```
inorder(node)
  if (node = null)
    return
  inorder(node.left)
  visit(node)
  inorder(node.right)
```


非递归,跟之前那个iterator有得一拼，其实好几个题都是在玩这个花样？

```
iterativeInorder(node)
  s ← empty stack
  while (not s.isEmpty() or node ≠ null)
    if (node ≠ null)
      s.push(node)
      node ← node.left
    else
      node ← s.pop()
      visit(node)
      node ← node.right
```
