Skip to content

Commit 23c3db5

Browse files
authored
[LEET] Daily Temperatures (Med)
1 parent 0339eb2 commit 23c3db5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

박예진/5주차/260127.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
vector<int> dailyTemperatures(vector<int>& temperatures) {
4+
stack<int> s; // idx
5+
int n = temperatures.size();
6+
vector<int> ans(n, 0);
7+
8+
for(int i = 0; i < temperatures.size(); i++){
9+
while(!s.empty() && temperatures[s.top()] < temperatures[i]) {
10+
int prev = s.top();
11+
s.pop();
12+
ans[prev] = i - prev;
13+
}
14+
s.push(i);
15+
}
16+
return ans;
17+
}
18+
};

0 commit comments

Comments
 (0)