<commit_before>package leetcode;

/**
 * https://leetcode.com/problems/second-minimum-node-in-a-binary-tree/
 */
public class Problem671 {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public int findSecondMinimumValue(TreeNode root) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem671 prob = new Problem671();

        TreeNode root = new TreeNode(2);
        root.left = new TreeNode(2);
        root.right = new TreeNode(5);
        root.right.left = new TreeNode(5);
        root.right.right = new TreeNode(7);
        System.out.println(prob.findSecondMinimumValue(root)); // 5

        root = new TreeNode(2);
        root.left = new TreeNode(2);
        root.right = new TreeNode(2);
        System.out.println(prob.findSecondMinimumValue(root)); // -1
    }
}<commit_msg>Update problem 671<commit_after>package leetcode;

/**
 * https://leetcode.com/problems/second-minimum-node-in-a-binary-tree/
 */
public class Problem671 {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public int findSecondMinimumValue(TreeNode root) {
        FirstSecondMinimum fsm = new FirstSecondMinimum();
        findSecondMinimumValue(root, fsm);
        return (fsm.secondMin == null || fsm.firstMin == fsm.secondMin) ? -1 : fsm.secondMin;
    }

    private static class FirstSecondMinimum {
        private Integer firstMin;
        private Integer secondMin;
    }

    private static void findSecondMinimumValue(TreeNode node, FirstSecondMinimum fsm) {
        if (node == null) {
            return;
        }
        if (fsm.firstMin == null) {
            fsm.firstMin = node.val;
        } else if (fsm.secondMin == null) {
            fsm.secondMin = node.val;
        } else {
            if (fsm.firstMin < node.val) {
                fsm.secondMin = fsm.firstMin;
                fsm.firstMin = node.val;
            } else if (fsm.secondMin < node.val) {
                fsm.secondMin = fsm.secondMin;
            }
        }
        findSecondMinimumValue(node.left, fsm);
        findSecondMinimumValue(node.right, fsm);
    }

    public static void main(String[] args) {
        Problem671 prob = new Problem671();

        TreeNode root = new TreeNode(2);
        root.left = new TreeNode(2);
        root.right = new TreeNode(5);
        root.right.left = new TreeNode(5);
        root.right.right = new TreeNode(7);
        System.out.println(prob.findSecondMinimumValue(root)); // 5

        root = new TreeNode(2);
        root.left = new TreeNode(2);
        root.right = new TreeNode(2);
        System.out.println(prob.findSecondMinimumValue(root)); // -1

        root = new TreeNode(2);
        root.left = new TreeNode(2);
        root.right = new TreeNode(5);
        root.right.left = new TreeNode(5);
        root.right.right = new TreeNode(7);
        root.right.right.left = new TreeNode(8);
        root.right.right.right = new TreeNode(8);
        System.out.println(prob.findSecondMinimumValue(root)); // 5
    }
}
{'fraction_non_alphanumeric': 0.11584800741427248, 'fraction_numerical': 0.015755329008341055, 'mean_word_length': 1.9981481481481482, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6704810', 'n_tokens_mistral': 1023, 'n_tokens_neox': 968, 'n_words': 215}