C++ Simple and clear code


#1
int dx[]={-1,0,0,1};
int dy[]={0,1,-1,0};

bool rangde(vector<string> &A, int i, int j, string B, int pos){
    int n = A.size();
    int m = A[0].size();
    if(pos==B.size())
    return true;
    
    if(i<0 or j<0 or i>=n or j>=m or A[i][j]!=B[pos])
    return false;
    
 
    for(int p=0;p<4;p++)
        if( rangde(A, i+dx[p], j+dy[p], B, pos+1))
            return true;

    return false;
}

int Solution::exist(vector<string> &A, string B) {
    
    int n = A.size();
    if(n==0)return (B.size()==0);
    int m = A[0].size();
    int ans=0;
    
    for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
        if(rangde(A,i,j,B,0))
            return 1;
            
    return 0;
}

#2

Simple and neat solution! Great!! :grinning::grinning:~