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 cbed122 commit be873c7Copy full SHA for be873c7
src/monotone/Problem739_DailyTemperature.java
@@ -0,0 +1,26 @@
1
+package monotone;
2
+
3
+import java.util.Stack;
4
5
+public class Problem739_DailyTemperature {
6
7
+ public int[] dailyTemperatures(int[] T) {
8
+ // (73, 7), --> remove
9
+ // (76, 6)
10
+ // (72, 5) --> remove
11
+ // (69, 4) --> remove
12
+ // (71, 3) --> remove
13
+ // (75, 2)
14
15
+ int n = T.length, res[] = new int[n];
16
+ Stack<Integer> stack = new Stack<>();
17
+ for (int i = n-1; i >= 0; i--) {
18
+ while (!stack.isEmpty() && T[stack.peek()] <= T[i]) {
19
+ stack.pop();
20
+ }
21
+ res[i] = stack.isEmpty() ? 0 : stack.peek()-i;
22
+ stack.push(i);
23
24
+ return res;
25
26
+}
0 commit comments