当前位置:网站首页>单调栈框架
单调栈框架
2022-07-22 02:28:00 【UniversalNature】
来自739. 每日温度,单调栈的典型应用场景是在一维数组中找第一个满足某种条件的数
public:
vector<int> dailyTemperatures(vector<int>& T) {
// 递增栈
stack<int> st;
vector<int> result(T.size(), 0);
st.push(0);
for (int i = 1; i < T.size(); i++) {
if (T[i] < T[st.top()]) {
// 情况一
st.push(i);
} else if (T[i] == T[st.top()]) {
// 情况二
st.push(i);
} else {
while (!st.empty() && T[i] > T[st.top()]) {
// 情况三
result[st.top()] = i - st.top();
st.pop();
}
st.push(i);
}
}
return result;
}
};
边栏推荐
- Succès de la construction du cluster expérimental tdengine
- TDengine学习笔记
- Bannertext (watermark text)
- MySQL(28)——事务相关
- Installation and use of tensorboard
- How to use first-hand data visualization to win the favor of the boss and grasp the key points of data visualization
- OpenSSL 自签名证书颁发脚本 —— 筑梦之路
- Shardingjdbc horizontal split table configuration
- Accelerate the construction of standard system and promote the high-quality development of data security industry
- A Recommendation for interface-based programming
猜你喜欢
MySQL練習一數據庫的知識
【C语言-文件】数据终于可以出内存,到外面的世界看看了/(ㄒoㄒ)/~~
JMeter notes 1 | introduction and architecture of JMeter
Introduction to microservices
PLT draw and save the results
Equal protection compliance 2022 series | one center + triple protection, helping the construction of enterprise level protection to be more scientific
Installation and use of tensorboard
AutoComplete(自动完成)
MySQL locking mechanism: MyISAM table lock, InnoDB row lock
Delete Nan points in 3D point cloud TXT file
随机推荐
MySQL locking mechanism: MyISAM table lock, InnoDB row lock
Let security move | no matter what industry network architecture, these six tactics win the target
DM8:查询达梦数据库数据文件使用大小限制
seaborn barplot画图总结
Barcode(条形码)
Kubernetes基础部分学习笔记
QT 动态dll的创建和调用
AutoLabel (AutoLabel)
What is exploratory testing? What are the methods of exploratory testing?
Graffiti Wi Fi & ble SoC development slide strip (6) -- slide strip function demonstration
res中values-swxxdp计算
OpenSSL self signed certificate issuance script -- the road to building a dream
ADB common commands
时序数据库
加快标准体系建设,促进数据安全产业高质量发展
golang语言cli库
Succès de la construction du cluster expérimental tdengine
Cookies and sessions
JS高级 之 ES6 实现继承
FPGA图像处理学习——人脸识别