```
def convertBST(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
p, stack, sum_ = root, [], 0
while p or stack:
if p:
stack.append(p)
p = p.right
else:
p = stack.pop()
p.val = sum_ = p.val + sum_
p = p.left
return root
```