Skip to content

Commit 0484cf5

Browse files
Create 739-Daily-Temperatures.java
1 parent 4f07eea commit 0484cf5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

java/739-Daily-Temperatures.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int[] dailyTemperatures(int[] temperatures) {
3+
int[] ans = new int[temperatures.length];
4+
Stack<Integer> stack = new Stack<>();
5+
for (int currDay = 0; currDay<temperatures.length; currDay++) {
6+
while (!stack.isEmpty() && temperatures[currDay]>temperatures[stack.peek()]) {
7+
int prevDay = stack.pop();
8+
ans[prevDay] = currDay-prevDay;
9+
}
10+
stack.add(currDay);
11+
}
12+
return ans;
13+
}
14+
}

0 commit comments

Comments
 (0)