Why does my answer get a Output Limit Exceeded error?

  • 0
    from collections import deque
    class Solution(object):
        def levelOrder(self, root):
            :type root: TreeNode
            :rtype: List[List[int]]
            if root is None:
                return []
            res = []
            queue = deque()
            p = root
            while queue:
                s = len(queue)
                level_nodes = []
                while s:
                    p = queue.popleft()
                    if p.left:
                    if p.right:
                    s -= 1
            return res

    Thank you very much!

  • 1

    Because you are returning wrong types, if you look at rtype in the docstring then you can see that it is supposed to be List[List[int]] but in your case it is List[List[TreeNode]]

  • 0

    Yes that's the problem. Thank you very much!!!

Log in to reply

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