mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Merge pull request #1380 from xiaofei-2020/mono01
添加(0739.每日温度.md):增加typescript版本
This commit is contained in:
@ -372,6 +372,32 @@ var dailyTemperatures = function(temperatures) {
|
||||
};
|
||||
```
|
||||
|
||||
TypeScript:
|
||||
|
||||
> 精简版:
|
||||
|
||||
```typescript
|
||||
function dailyTemperatures(temperatures: number[]): number[] {
|
||||
const length: number = temperatures.length;
|
||||
const stack: number[] = [];
|
||||
const resArr: number[] = new Array(length).fill(0);
|
||||
stack.push(0);
|
||||
for (let i = 1; i < length; i++) {
|
||||
let top = stack[stack.length - 1];
|
||||
while (
|
||||
stack.length > 0 &&
|
||||
temperatures[top] < temperatures[i]
|
||||
) {
|
||||
resArr[top] = i - top;
|
||||
stack.pop();
|
||||
top = stack[stack.length - 1];
|
||||
}
|
||||
stack.push(i);
|
||||
}
|
||||
return resArr;
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user