Boring
public class Solution { public TreeNode inorderSuccessor(TreeNode root, TreeNode p) { return helper(root, p, null); } public TreeNode helper(TreeNode root, TreeNode p, TreeNode pre) { if (root == p) { if (root.right != null) { TreeNode tmp = root.right; while (tmp.left != null) { tmp = tmp.left; } return tmp; } else { return pre; } } if (root.val < p.val && root.right != null) { return helper(root.right, p, pre); } else if (root.val > p.val && root.left != null) { return helper(root.left, p, root); } return null; } }
原文:http://www.cnblogs.com/vision-love-programming/p/4997450.html