Skip to content

Commit

Permalink
Q739 added.
Browse files Browse the repository at this point in the history
  • Loading branch information
isinsuarici committed Mar 11, 2023
1 parent 1f984a5 commit 28d835b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions M_739_DailyTemperatures.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public int[] dailyTemperatures(int[] temperatures) {
Stack<Integer> stack = new Stack<>();
int[] res= new int[temperatures.length];

for(int i=0;i<temperatures.length;i++){
while(!stack.isEmpty() && temperatures[stack.peek()]<temperatures[i]){
int x=stack.pop();
res[x]=i-x;
}
stack.push(i);
}
return res;
}
}

0 comments on commit 28d835b

Please sign in to comment.