# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = NoneclassSolution:defsumNumbers(self,root: TreeNode) ->int: res =0defdfs(node,path):if node isNone:return path.append(node.val)if node.left isNoneand node.right isNone:nonlocal resfor i, num inenumerate(path[::-1]): res += num *10** ielse:dfs(node.left, path)dfs(node.right, path) path.pop()dfs(root, [])return res