当前位置:网站首页>leetcode - 739. Daily temperature
leetcode - 739. Daily temperature
2022-06-11 08:43:00 【zmm_ mohua】
leetcode - 739. Daily temperature
subject

Code
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
// Monotonic stack
vector<int> dailyTemperatures(vector<int>& temperatures) {
int n = temperatures.size();
vector<int> res(n, 0);
stack<int> s;
for(int i = 0; i < n; i++){
while(!s.empty() && temperatures[i] > temperatures[s.top()]){
int index = s.top();
s.pop();
res[index] = i - index;
}
s.push(i);
}
return res;
}
// Time limit exceeded
vector<int> dailyTemperatures1(vector<int>& temperatures) {
int n = temperatures.size();
vector<int> res(n, 0);
for(int i = 0; i < n - 1; i++){
for(int j = i + 1; j < n; j++){
if(temperatures[i] < temperatures[j]){
res[i] = j - i;
break;
}
}
}
return res;
}
int main(){
int n;
cin>>n;
vector<int> res;
vector<int> temperatures(n);
for(int i = 0; i < n; i++){
cin>>temperatures[i];
}
res = dailyTemperatures(temperatures);
for(int i = 0; i < res.size(); i++){
cout<<res[i]<<" ";
}
return 0;
}
边栏推荐
- B+ super tree helps you know the underlying structure of MySQL
- Not eligible for getting processed by all beanpostprocessors
- Implementation of CRF for named entity recognition
- (resolved) pychart debug error -unicode decodeerror: 'UTF-8' codec can't decode byte 0xe8 in position 1023
- B+超强树,带你知晓MySQL的底层是怎样的结构
- AttributeError: module ‘tensorflow. compat. v2.__ internal__‘ has no attribute ‘register_ clear_ session_
- (the slow download speed of cifar10 in torchvision has been solved) how to download and use torchvision import
- Project training - clonemon
- 剑指 Offer 10- II. 青蛙跳台阶问题
- Zookepper===> animal management system
猜你喜欢

MySQL advanced features, you can read more about it and meet the interview

Web design and website planning assignment 13 making video playlists

Qiao lerna: lerna auxiliary tool

怎么做好项目管理?学会这4个步骤就够了

剑指 Offer 62. 圆圈中最后剩下的数字

命名实体识别之CRF的实现方式

Empty difference between postgrepsql and Oracle

剑指 Offer 51. 数组中的逆序对

补2:圆环回原点问题

@Usage details of postconstruct, initializingbean and initmethod
随机推荐
Web design and website planning assignment 12 online registration form
二、渲染 Camera 的数据
Asynchronous notification mechanism of character device driver
qiao-npms:获取npm包下载量
(completely solved) dataframe assignment settingwithcopywarning: a value is trying to be set on a copy of a slice
Redis cluster in Linux system
The role of lambdalr in pytorch
Introduction to knowledge atlas -- yedda annotation
Sign in system design: how to draw the sign in function
Uniapp turn off / on / adjust system sound
Process control: process waiting (recycling child processes)
GCC AVR(Atmel Studio+ AVR Studio)如何将结构体数组定义在程序存储器(flash)空间并进行读操作
Solve cannot import name 'multiheadattention' from 'tensorflow keras. layers‘
Zookepper===> animal management system
不想项目失控?你需要用对项目管理工具
用飞项进行目标管理,不做职场上的“无头苍蝇”
Bat batch processing separate environment packaging
(resolved) typeerror: meshgrid() got an unexpected keyword argument 'indexing‘
What is concurrent search set? Are you still worried about it? In fact, it is a problem of connected graph, which is not so difficult to understand
【CVPR2022】QueryDet论文精读