i am stuck on the spiral matrix problem, tried all changes in code but it still give the error runtime error: reference binding to misaligned address 0xbebebebebebebebe for type ‘int’, which requires 4 byte alignment (stl_vector.h)
0xbebebebebebebebe: note: pointer points here
added count< total in for loops,made seperate index for all loops but still error
class Solution {
public:
vector<int> spiralOrder(vector<vector<int>>& matrix) {
vector<int> ans;
int row=matrix.size();
int col=matrix[0].size();
int count=0;
int total=row*col;
int startrow=0;
int endrow=row-1;
int startcol=0;
int endcol=col-1;
while(count<total){
//starting row
for(int index1 =startcol;index1<=endcol && count<total;index1++){
ans.push_back(matrix[startrow][index1]);
startrow++;
count++;
}
//ending column
for(int index2=startrow;index2<=endrow && count<total;index2++ ){
ans.push_back(matrix[index2][endcol]);
endcol--;
count++;
}
//ending row
for(int index3=endcol;index3>=startcol && count<total;index3--){
ans.push_back(matrix[endrow][index3]);
endrow--;
count++;
}
//start column
for(int index4=endrow;index4>=startrow && count<total ;index4--){
ans.push_back(matrix[index4][startcol]);
startcol++;
count++;
}
}
return ans;
}
};
New contributor
user25081518 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4