给定一棵二叉树的其中一个节点,请找出中序遍历序列的下一个节点。
/** * 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->father->right == p) p = p->father; return p->father; } };
标签:right,TreeNode,一个,father,二叉树,节点,left From: https://www.cnblogs.com/leetothemoon/p/16971852.html