285. Inorder Successor in BST
作者:
夜皇雪 | 来源:发表于
2016-12-13 10:37 被阅读0次/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public TreeNode inorderSuccessor(TreeNode root, TreeNode p) {
if(root==null) return null;
if(root.val<=p.val){
return inorderSuccessor(root.right,p);
}else{
TreeNode left=inorderSuccessor(root.left,p);
return left==null? root:left;
}
}
}
本文标题:285. Inorder Successor in BST
本文链接:https://www.haomeiwen.com/subject/ouwvmttx.html
网友评论