Python 函数SumOfLongRootToLeafPath如何返回值

Python 函数SumOfLongRootToLeafPath如何返回值,python,data-structures,binary-tree,recursive-datastructures,Python,Data Structures,Binary Tree,Recursive Datastructures,我正在解决一些关于二叉树的问题,我陷入了这个问题 我正在使用python来解决这个问题 我理解链接中给出的解决方案的逻辑,但我的问题是,当SumOfLongRootToLeafPathUtil(root)函数没有返回任何内容时,SumOfLongRootToLeafPath()函数中的maxSum值是如何变化的 变量的原始值如何更改请帮助 ps:请参考链接中给出的python代码传递到SumOfLongRootToLeafPath函数的maxSum列表对象是可变的。因此,当它在该函数中更改时,S

我正在解决一些关于二叉树的问题,我陷入了这个问题 我正在使用python来解决这个问题 我理解链接中给出的解决方案的逻辑,但我的问题是,当SumOfLongRootToLeafPathUtil(root)函数没有返回任何内容时,SumOfLongRootToLeafPath()函数中的maxSum值是如何变化的 变量的原始值如何更改请帮助
ps:请参考链接中给出的python代码传递到
SumOfLongRootToLeafPath
函数的maxSum列表对象是可变的。因此,当它在该函数中更改时,
SumOfLongRootToLeafPathUtil
函数将看到对它的更改。因此,不需要返回值

e、 g.显示列表的可变性质

def change_it(value):
    value[0] = 12 # modify the list without creating a new one

value = [4]
print(value) # this will show [4]
change_it(value)
print(value) # this will show [12] as change_it has altered the value in the list
如果一个元组用于maxSum而不是列表,那么就必须从
SumOfLongRootToLeafPath
返回结果,因为元组是不可变的

e、 g.显示元组的不变性质

def change_it(value):
    value = (12, ) # can't modify the tuple, so create a new one

value = (4, )
print(value) # this will show (4,)
change_it(value)
print(value) # this will still show (4,) as change_it cannot modify the tuple

你能在这里发布相关的代码吗?这个链接可能会消失,从而使这个问题在将来变得无用。这个值在一个可变的列表对象中被更改。