mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
更新 0739.每日温度.md Python3代码
This commit is contained in:
@ -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:
|
||||
|
||||
> 暴力法
|
||||
|
Reference in New Issue
Block a user