Python DFS and very easy to understand


  • 0
    K
    class Solution(object):
        def __init__(self):
            self.res = []
        def findSecondMinimumValue(self, root):
            if not root:
                return []
            
            if root:
                self.res.append(root.val)
                self.findSecondMinimumValue(root.left)
                self.findSecondMinimumValue(root.right)
               
            return -1 if len(sorted(set(self.res))) == 1 else sorted(set(self.res))[1]
    

Log in to reply
 

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