# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def sumNumbers(self, root):
"""
:type root: TreeNode
:rtype: int
"""
if not root:
return 0
sum_ = list()
def helper(val,node):
tmp = node.val + 10*val
if not node.left and not node.right:
sum_.append(tmp)
if node.left:
helper(tmp,node.left)
if node.right:
helper(tmp,node.right)
helper(0,root)
print(sum_)
return sum(sum_)
树-129. 求根到叶子节点数字之和-PYTHON
最新推荐文章于 2023-06-24 13:53:39 发布