Skip to content

Commit db56b09

Browse files
committed
feat(Stack): ✨利用栈解决739
1 parent e907475 commit db56b09

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Queue/621/solution1.js

-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66
* Medium
77
*/
88
const leastInterval = (tasks, n) => {
9-
109
}

Stack/739/solution1.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* https://leetcode-cn.com/problems/daily-temperatures/
3+
*
4+
* 739. 每日温度
5+
*
6+
* Medium
7+
*
8+
* 140ms 100.00%
9+
* 42.6mb 44.44%
10+
*/
11+
const dailyTemperatures = T => {
12+
const max = T.length;
13+
const ans = new Array(max).fill(0);
14+
15+
const stack = [];
16+
17+
for (let i = 0, max = T.length; i < max; i++) {
18+
while(stack.length && T[i] > T[stack[stack.length - 1]]) {
19+
let index = stack.pop();
20+
ans[index] = i - index;
21+
}
22+
stack.push(i);
23+
}
24+
return ans;
25+
}

0 commit comments

Comments
 (0)