• 문제 링크
Second Minimum Node In a Binary Tree - LeetCode
Can you solve this real interview question? Second Minimum Node In a Binary Tree - Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub
leetcode.com
• 풀이 코드
public class Solution {
public int findSecondMinimumValue(TreeNode root) {
if (root == null || root.left == null) return -1;
int l = root.val == root.left.val ? findSecondMinimumValue(root.left) : root.left.val, r = root.val == root.right.val ? findSecondMinimumValue(root.right) : root.right.val;
return l != -1 && r != -1 ? Math.min(l, r) : Math.max(l, r);
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 680. Valid Palindrome II - Java (0) | 2026.09.22 |
|---|---|
| [LeetCode] 674. Longest Continuous Increasing Subsequence - Java (0) | 2026.09.21 |
| [LeetCode] 661. Image Smoother - Java (0) | 2026.09.19 |
| [LeetCode] 657. Robot Return to Origin - Java (0) | 2026.09.18 |
| [LeetCode] 653. Two Sum IV - Input is a BST - Java (0) | 2026.09.17 |
댓글