14,668,844 members
Rate this:
See more:
I am writing leetcode question 1019 (Next Greater Node In Linked List), using the class template provided by the leetcode website. At present, the code can run correctly on the official website. Today I want to execute it in my own compiler, but I don’t know how to write this type of print (cout). I would like to ask how to write print (cout) when encountering this type of class.

Below is my class code:

```class Solution {
public:
stack<int> s;
vector<int> a;
for (auto p = head; p; p = p->next) {
a.emplace_back(p->val);
}
vector<int> ans(a.size());
for (int i = 0; i < a.size(); ++i) {
while (s.size() && a[s.top()] < a[i]) {
auto top = s.top(); s.pop();
ans[top] = a[i];
}
s.push(i);
}
return ans;
}
};```

Beginners sincerely ask, maybe you can also attach your writing so that I can learn, thank you very much.

What I have tried:

Today I want to execute it in my own compiler, but I don’t know how to write this type of print (cout). I would like to ask how to write print (cout) when encountering this type of class. Beginners sincerely ask, maybe you can also attach your writing so that I can learn, thank you very much.
Posted
Updated 16-Sep-20 22:52pm
Amy Zhou 17-Sep-20 4:16am

Like the example input and output of Leetcode's official website.

Example 1:

Input: [2,1,5]
Output: [5,5,0]

Example 2:

Input: [2,7,4,3,5]
Output: [7,0,5,5,0]

Rate this:

Solution 2

To print an integer use the insertion operator `<<` with `cout`:
`cout << i << endl;`

To print a vector of integers use the same tecnique while iterating on all the vector items, e.g.
```for (size_t n = 0; n < v.size(); ++n)
{
cout << v[n] << " ";
}
cout << endl;
```

or
```for (auto  i : v)
{
cout << i << " ";
}
cout << endl;
```
v2
Rate this:

Solution 1

`cout` is pretty simple to use: 1.5 — Introduction to iostream: cout, cin, and endl | Learn C++[^]
Amy Zhou 17-Sep-20 4:18am

I know this, but how to match the title requirements is presented in "vector<int> nextLargerNodes(ListNode* head)" I don't understand...
Amy Zhou 17-Sep-20 4:20am

This is the input and output required by this question.
Rate this: