Skip to content

Instantly share code, notes, and snippets.

@chelsea1992
Last active April 17, 2017 03:23
Show Gist options
  • Save chelsea1992/6945a81a2603438acdeb51aa4b0d3094 to your computer and use it in GitHub Desktop.
Save chelsea1992/6945a81a2603438acdeb51aa4b0d3094 to your computer and use it in GitHub Desktop.
Leetcode
/**
* 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