This is DSA Question. I’m getting at error at runtime
error: reference binding to null pointer of type ‘int’ (stl_vector.h)
I’m getting this error in leetcode while submitting, but it is working fine in my local system.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define nl 'n'
#define py cout << "YES" << endl
#define pn cout << "NO" << endl
int main(){
vector<int> nums = {0,2,3,4,6,8,9};
int n = nums.size();
string str = to_string(nums[0]);
vector<string> ans;
for(int i=1; i<n; i++){
char lastChar = str[str.length()-1];
int no = lastChar - '0';
if(nums[i] == no+1){
if(str.length() > 1){
str[str.length() - 1] = '0' + nums[i];
}else{
str += "->" + to_string(nums[i]);
}
}else{
ans.push_back(str);
str = to_string(nums[i]);
}
}
ans.push_back(str);
for (auto &&i : ans)
{
cout << i << " ";
}
return 0;
}
13