Skip to content

Commit

Permalink
Added some code
Browse files Browse the repository at this point in the history
  • Loading branch information
codeAbinash committed Nov 14, 2023
1 parent a5d822f commit 70a24c6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions leetcode/problems/cpp/daily-temperatures.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// by @codeAbinash
// Time : O(n)
// Space : O(n)

#include "vector"
using namespace std;

class Solution {
public:
vector<int> dailyTemperatures(vector<int>& temperatures) {
int size = temperatures.size();
vector<int> ans(size, 0);
vector<int> stack;
for (int i = 0; i < size; i++) {
while (!stack.empty() && temperatures[stack.back()] < temperatures[i]) {
ans[stack.back()] = i - stack.back();
stack.pop_back();
}
stack.push_back(i);
}
return ans;
}
};

0 comments on commit 70a24c6

Please sign in to comment.