We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4f07eea commit 0484cf5Copy full SHA for 0484cf5
java/739-Daily-Temperatures.java
@@ -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