Skip to content

Commit 9e4c445

Browse files
committed
Question that i actually felt so good solving on my own, the euphoria you get on solving a problem you thought you wouldnt be able to solve yourself is something else
1 parent 717504a commit 9e4c445

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

‎739. Daily Temperatures.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class Solution {
2+
public:
3+
vector<int> dailyTemperatures(vector<int>& temperatures)
4+
{
5+
vector<int> count(temperatures.size(),0);
6+
7+
for(int i = temperatures.size()-2;i>=0;i--)
8+
{
9+
if(temperatures[i]<temperatures[i+1])
10+
{
11+
count[i] = 1;
12+
}
13+
else if(temperatures[i]>=temperatures[i+1] && count[i+1]==0)
14+
{
15+
count[i] = 0;
16+
}
17+
else if(temperatures[i]>=temperatures[i+1] && count[i+1]!=0)
18+
{
19+
int temp = i + count[i+1] + 1;
20+
while(temperatures[i]>=temperatures[temp] && count[temp]!=0)
21+
{
22+
temp+=count[temp];
23+
}
24+
25+
if(temperatures[i]>=temperatures[temp] && count[temp]==0)
26+
{
27+
count[i] = 0;
28+
}
29+
else
30+
{
31+
count[i] = temp-i;
32+
}
33+
}
34+
}
35+
return count;
36+
}
37+
};

0 commit comments

Comments
 (0)