Next Greater Node In Linked List LeetCode solution in C++
1class Solution {2public:3vector<int> nextLargerNodes(ListNode *head) {4vector<int> ans;5ListNode *curr = head;6if (head->next == NULL) {7ans.push_back(0);8return ans;9}1011while (curr != NULL) {12ListNode *next = curr->next;13while (next != NULL) {14if (next->val > curr->val) {15ans.push_back(next->val);16break;17}18next = next->next;19}20if (next == NULL) {21ans.push_back(0);22}23curr = curr->next;24}25return ans;26}27};