Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<int> nextGreaterElements(vector<int>& nums) {
- int n = nums.size();
- vector<int>res(n,-1);
- stack<int>st;
- for(int i=0;i<2*nums.size();i++)
- {
- while(!st.empty()&& nums[st.top()] < nums[i%n] )
- {
- res[st.top()] = nums[i%n];
- st.pop();
- }
- st.push(i%n);
- }
- return res;
- }
- };
Add Comment
Please, Sign In to add comment