I am solving this leetcode question -> https://leetcode.com/problems/next-greater-node-in-linked-list/`your
and this is showing error ->Line 172: Char 16: runtime error: reference binding to misaligned address 0xbebebebebebec0ba for type ‘int’, which requires 4 byte alignment (stl_deque.h)
0xbebebebebebec0ba: note: pointer points here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_deque.h:181:16
My code->
class Solution {
public:
vector<int> nextLargerNodes(ListNode* head) {
vector<int> v;
if(head->next==nullptr){
v.push_back(0);
return v;
}
int a;
vector<unsigned> ll;
while(head!=nullptr){
a=head->val;
ll.push_back(a);
head=head->next;
}
stack<int> s;
for(int i=ll.size()-1;i>=0;i--){
if(s.size()==0){
v.push_back(0);
}
else if(s.top()>ll[i]){
v.push_back(s.top());
}
else if(s.top()<ll[i]){
while(s.top()<=ll[i]){
if(s.size()!=0){
s.pop();}
}
if(s.size()==0){
v.push_back(0);
}
else{
v.push_back(s.top());}
}
s.push(ll[i]);
}
reverse(v.begin(),v.end());
return v;
}
};
Kamalpreet Singh Saini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.