'Getting error while using 2-d array through vectors
I was coding on leetcode and while doing so I got this error - "Line 1034: Char 9: runtime error: reference binding to null pointer of type 'int' (stl_vector.h)" Can anyone please help me where I am doing wrong. Below is my code
class Solution {
public:
int uniquePaths(int m, int n) {
vector<vector<int>> ans;
vector<int> help;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
vector<int> temp;
if(i==0||j==0)
{
temp.push_back(1);
}
else
{
temp.push_back(temp[j-1]+help[j]);
}
help=temp;
ans.push_back(temp);
}
}
return ans[m-1][n-1];
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
