https://leetcode.com/problems/next-greater-element-i/description/
class Solution { public: vector<int> nextGreaterElement(vector<int>& findNums, vector<int>& nums) { unordered_map<int,int> m; stack<int> st; for (int i = nums.size() - 1; i >= 0; i--) { int cur = nums[i]; while (!st.empty() && cur >= st.top()) st.pop(); if (st.empty()) m[cur] = -1; else m[cur] = st.top(); st.push(cur); } vector<int> res; for (auto i : findNums) res.push_back(m[i]); return res; } };