Login light

leetcode/102. 二叉树的层序遍历.md

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def levelOrder(self, root: TreeNode) -> List[List[int]]:
        retList = []
        self.getNode(0, root, retList)
        return retList
    
    def getNode(self, index, child: TreeNode, retList):
        if None == child:
            return
        if len(retList) < index + 1:
            retList.append([child.val])
        else:
            retList[index].append(child.val)
        self.getNode(index + 1, child.left, retList)
        self.getNode(index + 1, child.right, retList)