Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c819c0

Browse files
authored
Create 739-Daily-Temperatures
1 parent c16eb96 commit 2c819c0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

javascript/739-Daily-Temperatures

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

0 commit comments

Comments
 (0)