Last active
April 17, 2017 03:23
-
-
Save chelsea1992/6945a81a2603438acdeb51aa4b0d3094 to your computer and use it in GitHub Desktop.
Leetcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { | |
TreeNode res = null; | |
while(root!=null){ | |
if(root.val<=p.val){ | |
root = root.right; | |
} | |
else if(root.val>p.val){ | |
res = root; | |
root = root.left; | |
} | |
} | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment