Can someone help, what is wrong with my code?


#1

void findAdj(vector &A, int &n, int &m, int sx, int sy, int &res)
{
A[sx][sy]=0;
if(sx+1<n){
if(A[sx+1][sy]==‘X’){
findAdj(A,n,m,sx+1,sy,res);
}
}
if(sy+1<m){
if(A[sx][sy+1]==‘X’){
findAdj(A,n,m,sx,sy+1,res);
}
}
if(sx-1<n && sx-1>=0){
if(A[sx-1][sy]==‘X’){
findAdj(A,n,m,sx-1,sy,res);
}
}
if(sy-1<m && sy-1>=0){
if(A[sx][sy-1]==‘X’){
findAdj(A,n,m,sx,sy-1,res);
}
}

return;

}

void helper(vector &A, int &n,int &res){
int m=0;
for(int i=0;i<n;i++){
m=A[i].size();
int j=0;
while(A[i][j]!=’\0’){
if(A[i][j]==‘X’){
findAdj(A,n,m,i,j,res);
res+=1;
}
j++;
}
}
return;
}

int Solution::black(vector &A) {

int n=A.size();

int res=0;
helper(A,n,res);
return res;

}