min_val = root.val
        m = 12345678190000
        second = m

        def dfs(root):
            nonlocal second

            if root is None:
                return

            if root.val > min_val:
                second = min(second, root.val)
            else:
                dfs(root.left)
                dfs(root.right)

        dfs(root)

        return second if second != m else -1


sl = Solution()
root = '[2,2,5,null,null,5,7]'
root = '[2,2,2]'
root = '[1,1,3,1,1,3,4,3,1,1,1,3,8,4,8,3,3,1,6,2,1]'
root = '[2,2,3]'
root = TreeNode.fromStrList(root)
TreeNode.travel(root)
print(sl.findSecondMinimumValue(root))
Example #2
0
class Solution:
    def increasingBST(self, root: TreeNode) -> TreeNode:
        out = None
        pre = None

        def midorder(root):
            if root is None:
                return
            midorder(root.left)
            nonlocal pre
            root.left = None

            if pre is not None:
                pre.right = root
            else:
                nonlocal out
                out = root
            pre = root
            midorder(root.right)

        midorder(root)

        return out


inp = '[2,1,4,null,null,3]'
root = TreeNode.fromStrList(inp)
sl = Solution()
out = sl.increasingBST(root)
TreeNode.travel(out)