/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
vector<int> nextLargerNodes(ListNode* head) {
vector<int> v,res;
if(head==NULL)
return v;
while(head!=NULL)
{
v.push_back(head->val);
res.push_back(0);
head=head->next;
}
int len=v.size();
stack<int> st;
for(int i=len-1;i>=0;i--)
{
while(!st.empty()&&st.top()<=v[i])
st.pop();
if(st.empty())
res[i]=0;
else
res[i]=st.top();
st.push(v[i]);
}
return res;
}
};