Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public TreeNode inorderSuccessor(TreeNode root, TreeNode p) {
- TreeNode node = root;
- TreeNode result = null;
- while(node!=null){
- if(node.val>p.val){
- if(result==null || node.val<result.val) result = node;
- node = node.left;
- }else node = node.right;
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement