java.lang.Object
g0601_0700.s0671_second_minimum_node_in_a_binary_tree.Solution

public class Solution extends Object
671 - Second Minimum Node In a Binary Tree.<p>Easy</p> <p>Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly <code>two</code> or <code>zero</code> sub-node. If the node has two sub-nodes, then this node&rsquo;s value is the smaller value among its two sub-nodes. More formally, the property <code>root.val = min(root.left.val, root.right.val)</code> always holds.</p> <p>Given such a binary tree, you need to output the <strong>second minimum</strong> value in the set made of all the nodes&rsquo; value in the whole tree.</p> <p>If no such second minimum value exists, output -1 instead.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/10/15/smbt1.jpg" alt="" /></p> <p><strong>Input:</strong> root = [2,2,5,null,null,5,7]</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> The smallest value is 2, the second smallest value is 5.</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/10/15/smbt2.jpg" alt="" /></p> <p><strong>Input:</strong> root = [2,2,2]</p> <p><strong>Output:</strong> -1</p> <p><strong>Explanation:</strong> The smallest value is 2, but there isn&rsquo;t any second smallest value.</p> <p><strong>Constraints:</strong></p> <ul> <li>The number of nodes in the tree is in the range <code>[1, 25]</code>.</li> <li><code>1 <= Node.val <= 2<sup>31</sup> - 1</code></li> <li><code>root.val == min(root.left.val, root.right.val)</code> for each internal node of the tree.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • findSecondMinimumValue

      public int findSecondMinimumValue(TreeNode root)