Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. class Solution {
  2. public TreeNode inorderSuccessor(TreeNode root, TreeNode p) {
  3. return inorderSuccessor(root, new TreeNode[]{p});
  4. }
  5. private TreeNode inorderSuccessor(TreeNode node, TreeNode[] p){
  6. if (node==null) return null;
  7. TreeNode left= inorderSuccessor(node.left, p);
  8. if (left!=null) return left;
  9. if (p[0]==null) return node;
  10. if (p[0]==node) p[0]= null;
  11. return inorderSuccessor(node.right, p);
  12. }
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement