转换函数将二叉树转换为链表。由于使用全局变量,我无法通过 geeksforgeek 中的测试用例。如何避免使用全局变量?
prev = None
head = None
def convert(root):
global prev
global head
if root is None:
return
convert(root.left)
if head== None:
head = root
prev = root
else:
root.left = prev
prev.right = root
prev = root
convert(root.right)
德玛西亚99
holdtom
相关分类