Python solution


  • 0
    H
    class Solution(object):
        def levelOrderBottom(self, root):
            """
            :type root: TreeNode
            :rtype: List[List[int]]
            """
            retList=[]
            self.travel(root,1,retList)
            return retList
      
        def travel(self,root,level,retList):
            if root is None :
                return False
            if len(retList) < level:
                retList.insert(0,[])
            idx = len(retList)-level
            retList[idx].append(root.val)
            self.travel(root.left,level+1,retList)
            self.travel(root.right,level+1,retList)
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.