Simple Python Solution


  • 0
    F
    class Solution(object):
        def levelOrderBottom(self, root):
            """
            :type root: TreeNode
            :rtype: List[List[int]]
            """
            if root ==None:
                return []
            
            arr = []
            self.traversalDeep(root,0,arr)
            
            arr.reverse()
            
            return arr
        
        def traversalDeep(self,node,deep,list):
            
            if deep<len(list):
                list[deep].append(node.val)
            else:
                list.append([node.val])
            
            if node.left:
                self.traversalDeep(node.left,deep+1,list)
                
            if node.right:
                self.traversalDeep(node.right,deep+1,list)
    

Log in to reply
 

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