1 class Solution: 2 def __init__(self): 3 self.L = list() 4 5 def inOrder(self,node): 6 if node!=None: 7 if node.left != None: 8 self.inOrder(node.left) 9 10 self.L.append(node) 11 12 if node.right != None: 13 self.inOrder(node.right) 14 15 def bstToGst(self, root: TreeNode) -> TreeNode: 16 self.inOrder(root) 17 sums = 0 18 for i in range(len(self.L)-1,-1,-1): 19 sums += self.L[i].val 20 self.L[i].val = sums 21 22 return root