题解 | #牛的生长情况#
牛的生长情况
https://www.nowcoder.com/practice/5f67258999bd4e61a361f4d3017a3fd4
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param weights int整型vector
* @return int整型vector
*/
vector<int> weightGrowth(vector<int>& weights) {
// write code here
int size = weights.size();
vector<int> res(size, -1);
stack<int> stk;
stk.push(0);
for (int i = 1; i < size; i++) {
while (stk.size() && weights[i] > weights[stk.top()]) {
res[stk.top()] = i-stk.top();
stk.pop();
}
stk.push(i);
}
return res;
}
};

SHEIN希音公司福利 283人发布