更新 0739.每日温度.md Python3代码

This commit is contained in:
lichun-chen 2021-07-07 20:47:03 -05:00 committed by GitHub
parent b4d2f98bc7
commit c369db528f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 1 deletions

View File

@ -211,7 +211,24 @@ Java
}
```
Python
''' Python3
class Solution:
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
answer = [0]*len(temperatures)
stack = [0]
for i in range(1,len(temperatures)):
# 情况一和情况二
if temperatures[i]<=temperatures[stack[-1]]:
stack.append(i)
# 情况三
else:
while len(stack) != 0 and temperatures[i]>temperatures[stack[-1]]:
answer[stack[-1]]=i-stack[-1]
stack.pop()
stack.append(i)
return answer
'''
Go
> 暴力法