题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
/**
* 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:
int cnt=0;
const int N=10010;
vector<TreeNode*> tre;
void dfs(TreeNode* p){
if(p){
dfs(p->left);
tre.push_back(p);
dfs(p->right);
}
}
TreeNode* inorderSuccessor(TreeNode* p) {
auto f=p;
while(p->father){
p=p->father;
}
dfs(p);
int a=f->val;
int b=-1;
for(int i=0;i<tre.size();i++){
// cout<<tre[i]->val<<" ";
b=tre[i]->val;
if(!(a-b)){
if(i<tre.size()-1){
return tre[i+1];
}
else{
return NULL;
}
}
}
}
};
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla