Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function dailyTemperatures(temperatures) {
- const arrTemp = new Array(temperatures.length).fill(0);
- const stack = [];
- for (let i = 0; i < temperatures.length; i++) {
- while(stack.length > 0 && stack[stack.length - 1][0] < temperatures[i]) {
- const currentNum = stack.pop();
- arrTemp[currentNum[1]] = i - currentNum[1];
- }
- // store temperature and idx of current element
- stack.push([temperatures[i], i]);
- }
- return arrTemp;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement