1class Solution {2int ans = Integer.MAX_VALUE;3boolean x = true;45public int findSecondMinimumValue(TreeNode root) {6go(root);7return x ? -1 : ans;8}910private void go(TreeNode root) {11if (root == null) return;12if (root.left != null) {13if (root.left.val == root.val) go(root.left);14else {15x = false;16ans = Math.min(ans, root.left.val);17}18}19if (root.right != null) {20if (root.right.val == root.val) go(root.right);21else {22x = false;23ans = Math.min(ans, root.right.val);24}25}26}27}