Python One-pass Inorder Traversal


  • 1
    class Solution(object):
        def __init__(self):
            self.lSum = 0
        def convertBST(self, root):
            """
            :type root: TreeNode
            :rtype: TreeNode
            """
            if not root:
                return None
            self.convertBST(root.right)
            self.lSum += root.val
            root.val = self.lSum
            self.convertBST(root.left)
            return root
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.