leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1019.cpp (503B)
0 class Solution {
1 public:
2 vector<int> nextLargerNodes(ListNode *head) {
3 if (!head) return {};
5 int len = 0, i = 0;
6 vector<int> res;
7 stack<pair<int, int>> st;
9 for (ListNode *p = head; p; p = p->next, i++) {
10 res.push_back(0);
11 while (!st.empty() && p->val > st.top().first) {
12 res[st.top().second] = p->val;
13 st.pop();
14 }
15 st.push({p->val, i});
16 }
17 return res;
18 }
19 };