网站发帖功能怎么做,金融公司网站制作,django开发的公司网站,wordpress 导出数据1. 题目链接2. 题目描述3. 解题方法4. 代码 1. 题目链接
739. 每日温度
2. 题目描述 3. 解题方法
用一个栈st保存每个数的下标#xff0c;同时创建一个数组res保存结果#xff0c;初始值都为0。循环遍历题目中的数组temperature。如果temperature[i] st.top()#x… 1. 题目链接2. 题目描述3. 解题方法4. 代码 1. 题目链接
739. 每日温度
2. 题目描述 3. 解题方法
用一个栈st保存每个数的下标同时创建一个数组res保存结果初始值都为0。循环遍历题目中的数组temperature。如果temperature[i] st.top()证明碰到了下一个更高温度。此时弹出st.top()然后记录结果。记得将遍历的temperature[i]的下标放入栈中。
4. 代码
class Solution {
public:vectorint dailyTemperatures(vectorint temperatures) {stackint st;int n temperatures.size();vectorint res(n);for(int i 0; i n; i){while(!st.empty() temperatures[st.top()] temperatures[i]){int top st.top();st.pop();res[top] i - top;}st.push(i);}return res;}
};最后附上我的打卡记录希望各位大佬可以监督我。