Skip to content

作业 #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Create 671_12
  • Loading branch information
hijkoo authored Apr 27, 2019
commit cac2b1195c6c00aac6c3b8deb467cf7d5086e887
31 changes: 31 additions & 0 deletions Week_02/id_12/671_12
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public int findSecondMinimumValue(TreeNode root) {
return traversal(root,root.val);
}

private int traversal(TreeNode root,int value){
if(root == null){
return -1;
}
if(root.val > value){
return root.val;
}
int l = traversal(root.left,value);
int r = traversal(root.right,value);

if(l>=0 && r>=0){
return Math.min(l,r);
}
return Math.max(l,r);
}

}