class Solution {
public:
vector<TreeNode*> record;
void DFS(TreeNode* p){
if(!p) return;
DFS(p->left);
record.push_back(p);
DFS(p->right);
}
TreeNode* inorderSuccessor(TreeNode* p) {
if(!p) return NULL;
auto cur = p;
while(p->father) p = p->father;
DFS(p);
int i = 0;
for(;i < record.size();i++){
if(record[i] == cur){
break;
}
}
return (i < record.size() - 1)?record[i+1]:NULL;
}
};