Guest User

Untitled

a guest
Nov 19th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. # Definition for a binary tree node.
  2. # class TreeNode(object):
  3. # def __init__(self, x):
  4. # self.val = x
  5. # self.left = None
  6. # self.right = None
  7.  
  8. class Solution(object):
  9. def findSecondMinimumValue(self, root):
  10. """
  11. :type root: TreeNode
  12. :rtype: int
  13. """
  14. res = self.findSecondMinimumValues(root)
  15. return res if res != float('inf') else -1
  16. def findSecondMinimumValues(self, root, min1 = float('inf'), min2 = float('inf')):
  17. if not root: return min2
  18. min1 = min(root.val, min1)
  19. if min1 < root.val < min2: min2 = root.val
  20. return min(self.findSecondMinimumValues(root.left, min1, min2),
  21. self.findSecondMinimumValues(root.right, min1, min2))
Add Comment
Please, Sign In to add comment