题目:
题解:
class Solution:def sumNumbers(self, root: TreeNode) -> int:if not root:return 0total = 0nodeQueue = collections.deque([root])numQueue = collections.deque([root.val])while nodeQueue:node = nodeQueue.popleft()num = numQueue.popleft()left, right = node.left, node.rightif not left and not right:total += numelse:if left:nodeQueue.append(left)numQueue.append(num * 10 + left.val)if right:nodeQueue.append(right)numQueue.append(num * 10 + right.val)return total