error
1034: Char 34: runtime error: applying non-zero offset 24 to null pointer (stl_vector.h) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_vector.h:1043:34
question is Given an integer array nums of unique elements, return all possible subsets (the power set).
Here is my code
vector<vector<int>> subsets(vector<int>& nums) {
vector<vector<int>>v;
for(int i=0;i<((1<<nums.size()));i++)
{
for(int j=0;j<nums.size();j++)
{
if(j>i) break;
if(i & (1<<j)) v[i].push_back(nums[j]);
}
}
return v;
}
I not getting where is error
Aucun commentaire:
Enregistrer un commentaire