Skip to content

Commit

Permalink
Merge pull request neetcode-gh#995 from andra961/main
Browse files Browse the repository at this point in the history
Create: 739-Daily-Temperatures.ts
  • Loading branch information
Ahmad-A0 authored Sep 2, 2022
2 parents 484be5e + 80f2565 commit c3e8ec6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions typescript/739-Daily-Temperatures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function dailyTemperatures(temperatures: number[]): number[] {
let stack = [];

let result = new Array(temperatures.length).fill(0);

for (let i = 0; i < temperatures.length; i++) {
let currTemp = temperatures[i];

while (stack.length > 0 && currTemp > stack[stack.length - 1].temp) {
let { ind } = stack.pop();
result[ind] = i - ind;
}

stack.push({ temp: currTemp, ind: i });
}

return result;
}

0 comments on commit c3e8ec6

Please sign in to comment.