vector<int> nextGreaterNum(const vector<int> &nums)
{
vector<int> res(nums.size(), 0);
stack<int> s;
for (int i = nums.size() - 1; i >= 0; i--)
{
while (!s.empty() and s.top() <= nums[i])
s.pop();
res[i] = s.empty() ? -1 : s.top();
s.push(nums[i]);
}
return res;
}
vector<int> nextGreaterNumPos(const vector<int> &nums)
{
vector<int> res(nums.size(),0);
stack<int> s;
for (int i = nums.size() - 1; i >= 0; i--)
{
while (!s.empty() and nums[s.top()] <= nums[i])
s.pop();
res[i] = s.empty() ? 0 : (s.top()-i);
s.push(i);
}
return res;
}
int main() {
//string a = "10";
//string b = "23";
//cout << multiply(a, b) << endl;
int nums1[5] = { 1,3,2,5,4 };
vector<int> nums;
for (int i = 0; i < 5; i++)
nums.push_back(nums1[i]);
vector<int> res;
res = nextGreaterNum(nums);
for (auto i : res)
cout << i << " ";
cout << endl;
return 0;}