### 102. Binary Tree Level Order Traversal

题目:

<https://leetcode.com/problems/binary-tree-level-order-traversal/>


难度:

Medium

第一种做法：利用curLevel和nextLevel来记录，然后按层append.


```python
class Solution(object):
    def levelOrder(self, root):
        """
        :type root: TreeNode
        :rtype: List[List[int]]
        """
        if not root:
            return []
        res, cur_level = [], [root]
        while cur_level:
            next_level, tmp_res = [], []
            for node in cur_level:
                tmp_res.append(node.val)
                if node.left:
                    next_level.append(node.left)
                if node.right:
                    next_level.append(node.right)
            res.append(tmp_res)
            cur_level = next_level
        return res
```


第二种做法：递归



```python
class Solution(object):
    def levelOrder(self, root):
        """
        :type root: TreeNode
        :rtype: List[List[int]]
        """
        res = []
        self.iter_order(root, 0, res)
        return res
    
    def iter_order(self, root, level, res):
        if not root: return
        if len(res) < level + 1:
            res.append([])
        res[level].append(root.val)
        self.iter_order(root.left, level+1, res)
        self.iter_order(root.right, level+1, res)
```
用递归来记录每一层，需要更加学习，不算easy
