Wrong solution got accepted! Very weak testcases


#1

void solve(TreeNode *a,int &ans){
if(a==NULL) return;
if(a->left==NULL and a->right==NULL) return;
if(a->left==NULL){
if(a->right->left!=NULL or a->right->right!=NULL) ans=0;
return;
}
if(a->right==NULL){
if(a->left->left!=NULL or a->left->right!=NULL) ans=0;
return;
}
solve(a->left,ans);
solve(a->right,ans);
}

int Solution::isBalanced(TreeNode* a) {
int ans=1;
solve(a,ans);
return ans;
}

I submitted this code and it got accpeted but after sometime i realised it is wrong and leetcode is also giving WA . So it’s better if you cross check your solution.