my Python Solution


  • 0
    B

    class Solution(object):
    def levelOrderBottom(self, root):

        q = []
        res = []
        last = 0
        if root is None:
            return []
        q.append(root)
        last =1
        tmpRes = []
        while len(q) != 0:
            tmpNode = q.pop(0)
            tmpRes.append(tmpNode.val)
    
            if tmpNode.left is not None:
                q.append(tmpNode.left)
            if tmpNode.right is not  None:
                q.append(tmpNode.right)
    
            last -= 1
            if last == 0:
                res.append(tmpRes)
                tmpRes = []
                last = len(q)
    
        return res[::-1]

Log in to reply
 

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