Simple iterative Python O(n) solution


  • 3
    S
        def levelOrderBottom(self, root):
            if not root: return []
            queue, nodes = [root], []
            while queue:
                nodes.append([q.val for q in queue])
                queue = [q for node in queue for q in (node.left, node.right) if q]
            nodes.reverse()
            return nodes

Log in to reply
 

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