Help!Time Limit Exceeded!


  • 0
    G
    class Solution(object):
    def levelOrder(self, root):
        if root is None:
            return []
        queue=[]
        queue.append(root)
        result=[]
        level=[]
        while len(queue)>0:
            check=len(queue)
            for i in range(0,check):
                tmp=queue.pop(0)
                level.append([tmp.val])
                if tmp.left is not None:
                    queue.append(tmp.left)
                if tmp.right is not None:
                    queue.append(tmp.right)
            result.append(level)    
        return result

Log in to reply
 

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