What is the time compelexity of my code


#1

bool check(TreeNode* A,int n){
if(A==NULL){
return false;
}
if(A->val==n){
return true;
}
return check(A->left,n)||check(A->right,n);
}
int ann(TreeNode* A,int b,int c){
if((A->val==b&&check(A,c))||(A->val==c&&check(A,b))){
return A->val;
}
bool bleft=check(A->left,b);
bool bright=check(A->right,b);
bool cleft=check(A->left,c);
bool cright=check(A->right,c);
if(bleft&&cleft){
return ann(A->left,b,c);
}
else if(bright&&cright){
return ann(A->right,b,c);
}
else if((bleft&&cright)||(bright&&cleft)){
return A->val;
}
else{
return -1;
}
}
int Solution::lca(TreeNode* A, int b, int c) {
return ann(A,b,c);
}