Skip to content

Commit c3e8ec6

Browse files
authored
Merge pull request neetcode-gh#995 from andra961/main
Create: 739-Daily-Temperatures.ts
2 parents 484be5e + 80f2565 commit c3e8ec6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

typescript/739-Daily-Temperatures.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function dailyTemperatures(temperatures: number[]): number[] {
2+
let stack = [];
3+
4+
let result = new Array(temperatures.length).fill(0);
5+
6+
for (let i = 0; i < temperatures.length; i++) {
7+
let currTemp = temperatures[i];
8+
9+
while (stack.length > 0 && currTemp > stack[stack.length - 1].temp) {
10+
let { ind } = stack.pop();
11+
result[ind] = i - ind;
12+
}
13+
14+
stack.push({ temp: currTemp, ind: i });
15+
}
16+
17+
return result;
18+
}

0 commit comments

Comments
 (0)