网站制作品牌有哪些,八百客crm系统登录入口,如何搭建一个简单的网站,石家庄根据每日 气温 列表#xff0c;请重新生成一个列表#xff0c;对应位置的输出是需要再等待多久温度才会升高超过该日的天数。如果之后都不会升高#xff0c;请在该位置用 0 来代替。
例如#xff0c;给定一个列表 temperatures [73, 74, 75, 71, 69, 72, 76, 73]#xf…根据每日 气温 列表请重新生成一个列表对应位置的输出是需要再等待多久温度才会升高超过该日的天数。如果之后都不会升高请在该位置用 0 来代替。
例如给定一个列表 temperatures [73, 74, 75, 71, 69, 72, 76, 73]你的输出应该是 [1, 1, 4, 2, 1, 1, 0, 0]。
提示气温 列表长度的范围是 [1, 30000]。每个气温的值的均为华氏度都是在 [30, 100] 范围内的整数。
class Solution {
public:vectorint dailyTemperatures(vectorint T) {int n T.size();vectorint res(n), next(101, INT_MAX);for (int in-1; i0; --i) {int warmerIndex INT_MAX;for(int jT[i]1; j100; j) {warmerIndex min(warmerIndex, next[j]);}if (warmerIndex ! INT_MAX) {res[i] warmerIndex - i;}next[T[i]] i;}return res;}
};class Solution {
public:vectorint dailyTemperatures(vectorint T) {int n T.size();vectorint ans(n);stackint s;for (int i 0; i n; i) {while (!s.empty() T[i] T[s.top()]) {int previousIndex s.top();ans[previousIndex] i - previousIndex;s.pop();}s.push(i);}return ans;}
};class Solution {
public:vectorint dailyTemperatures(vectorint T) {int n T.size();vectorint res(n);stackint s;int i 0;while(i n) {if (s.empty() || T[s.top()] T[i]) {s.push(i);i;} else {res[s.top()] i - s.top();s.pop();}}}return res;
}来源力扣LeetCode