1. Code

class Solution:
    def __init__(self):
        self.sum = 0

    def addNode(self, node):
        # Calculate from the deepest node on the right and gradually move to the lower left node.
        if node.right:
            self.addNode(node.right)
        node.val += self.sum
        self.sum = node.val
        if node.left:
            self.addNode(node.left)

    def bstToGst(self, root: TreeNode) -> TreeNode:
        self.addNode

2. Result

        Runtime : 16 ms(99.69%), Memory usage : 14 MB(95.11%)
        (Runtime can be different by a system even if it is a same code.)

Check out the my GitHub repo for more info on the code. If you have questions, you can leave a reply on this post.