/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode *father;
* TreeNode(int x) : val(x), left(NULL), right(NULL), father(NULL) {}
* };
*/
class Solution {
public:
TreeNode* inorderSuccessor(TreeNode* p) {
if(p->right)//如果有右儿子,找到右子树最左侧的点
{
p=p->right;
while(p->left) p=p->left;
return p;
}
//否则向右上找父节点
while(p->father&&p!=p->father->left)
p=p->father;
return p->father;
}
};
标签:right,TreeNode,一个,father,二叉树,NULL,节点,left
From: https://www.cnblogs.com/tangxibomb/p/17210577.html