Easy recursive approach in C++


#1

void helper(vector<vector > &A,bool vis[100][100],int i,int j,int &count)
{
if(i>=A.size() || j>=A[0].size() || i<0 || j<0 || vis[i][j]==true || A[i][j]
==1)
{
return;
}
if(i==A.size()-1 && j==A[0].size()-1)
{
count++;
return;
}
vis[i][j]=true;
helper(A,vis,i+1,j,count);
helper(A,vis,i,j+1,count);
vis[i][j]=false;
}

int Solution::uniquePathsWithObstacles(vector<vector > &A)
{
int count=0;
bool vis[100][100];
memset(vis,false,sizeof(vis));
helper(A,vis,0,0,count);
return count;
}