What's wrong with the comma?(python)

  • 0
    class Solution(object):
        def minDepth(self, root):
            if not root: return 0
            queue = collections.deque([(root, 1)])
            while queue:
                node, step = queue.popleft()
                if not node.left and not node.right:
                    return step
                if node.left:
                    queue += (node.left, step + 1),
                if node.right:
                    queue += (node.right, step + 1),
    i saw this from other people's answer,when i did it,i didn't use ',' the online testing system shows
    Runtime Error Message:
    Line 44: TypeError: 'TreeNode' object is not iterable 
    Last executed input:

  • 0

    You need , because it uses tuple append with one value.

Log in to reply

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