Merge pull request #2008 from mercer5/master

添加0739每日温度 python 精简版本
This commit is contained in:
程序员Carl 2023-04-17 10:36:12 +08:00 committed by GitHub
commit 60715a7fa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -271,6 +271,7 @@ class Solution {
```
Python
> 未精简版本
```python
class Solution:
@ -291,6 +292,21 @@ class Solution:
return answer
```
> 精简版本
```python
class Solution:
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
answer = [0]*len(temperatures)
stack = []
for i in range(len(temperatures)):
while len(stack)>0 and temperatures[i] > temperatures[stack[-1]]:
answer[stack[-1]] = i - stack[-1]
stack.pop()
stack.append(i)
return answer
```
Go
> 暴力法