Merge pull request #1380 from xiaofei-2020/mono01

添加(0739.每日温度.md):增加typescript版本
This commit is contained in:
程序员Carl
2022-06-19 09:50:49 +08:00
committed by GitHub

View File

@ -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;
};
```