Simple Readable Python Solution


  • 0
    M
        def findSecondMinimumValue(self, root):
            """
            :type root: TreeNode
            :rtype: int
            """
            vals = []
            def getNodes(node):
                if node:
                    vals.append(node.val)
                    if node.left:
                        getNodes(node.left)
                    if node.right:
                        getNodes(node.right)
            
            getNodes(root)
            
            vals.sort()
            for i in xrange(len(vals) - 1):
                if vals[i] != vals[i+1]:
                    return vals[i+1]
            
            return -1
    

Log in to reply
 

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