I am not getting why the code shoes runtime error


#1

vector<vector > Solution::solve(int A) {
vector<vector >vec(A);
for(int i=0;i<A;i++)
{
for(int j=0;j<=i;j++)
{
if(j==0||j==i)
{
vec[i][j]=1;
}
else
{
vec[i][j]=vec[i-1][j-1]+vec[i-1][j];
}
}

}
return vec;

}


#2

@sandeep-kumar_591 there are few errors in your code:

  1. Please mention the data type you want to store in vector. For eg :- vector<vector>
  2. It’s showing runtime error because you did not declare the size of the inner vector and directly accessing the location (like v[i][j]). Instead, use push_back() function (it will work).