Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Definition for a binary tree node.
- # class TreeNode(object):
- # def __init__(self, x):
- # self.val = x
- # self.left = None
- # self.right = None
- class Solution(object):
- def findSecondMinimumValue(self, root):
- """
- :type root: TreeNode
- :rtype: int
- """
- res = self.findSecondMinimumValues(root)
- return res if res != float('inf') else -1
- def findSecondMinimumValues(self, root, min1 = float('inf'), min2 = float('inf')):
- if not root: return min2
- min1 = min(root.val, min1)
- if min1 < root.val < min2: min2 = root.val
- return min(self.findSecondMinimumValues(root.left, min1, min2),
- self.findSecondMinimumValues(root.right, min1, min2))
Add Comment
Please, Sign In to add comment