5 lines python solution


  • 1
    C
    class Solution(object):
        def levelOrder(self, root):
            """
            :type root: TreeNode
            :rtype: List[List[int]]
            """
            nodes, vals = [root] if root else [], []
            while nodes:
                vals.append(map(lambda x:x.val, nodes))
                nodes = filter(lambda x: x, [i for j in nodes if j for i in [j.left, j.right]])
            return vals
                    
    

Log in to reply
 

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