#include <stack>
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param nums int整型vector
* @return int整型vector
*/
vector<int> nextBigger(vector<int>& nums) {
// write code here
stack<int> st;
int n = nums.size();
vector<int> ret(n, -1);
for(int i = 0; i < 2 * n -1; ++i){
while(!st.empty() && nums[i%n] > nums[st.top()]){
ret[st.top()] = nums[i%n];
st.pop();
}
st.push(i%n);
}
return ret;
}
};

京公网安备 11010502036488号