Second Minimum Node In a Binary Tree

Given a special binary tree where each node has either two or zero sub-nodes, and each node's value is the smaller value between its two sub-nodes, find the second minimum value in the tree. If no such value exists, return -1.

Constraints

  • The number of nodes in the tree is in the range [1, 25].
  • 1 <= Node.val <= 2^31 - 1
  • root.val == min(root.left.val, root.right.val) for each internal node of the tree.
Saving… · 9 lines
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right

class Solution:
def findSecondMinimumValue(self, root: TreeNode) -> int:
Console

Click Run to execute sample tests.