Plz tell whats wrong with this code?(showing runtime error)


#1

vector<vector > Solution::solve(int A) {
vector<vector > a;
if(A==0){
return a;
}
for(int i=1;i<=A;i++){
vector x;
for(int k=1;k<=i;k++){

        x.push_back(0);
        if(k==1||k==i){
            x[k]==1;
            //x.push_back(1);
        }
    }
    a.push_back(x);
}


for(int i=3;i<=A;i++){
    for(int h=2;h<=i-1;h++){
        a[i][h]=(a[i-1][h]+a[i-1][h-1]);
    }
}


return a;

}


#2

HI there. I think the Error in your code is : U did not declare a 2d vector in first place !

syntax for 2d vector is : vector<vector<int.> VectorName ;

try the above syntax.


#3

you need to declare the size of 2d vector.
correct syntax would be vector<vector> a(n);