华为算法岗笔试2024届秋招
1.力扣739.每日温度,使用单调栈,使用for循环不知道为什么会超时,使用while不会(看看有没有大佬知道为啥)
class Solution(object):
def dailyTemperatures(self, temperatures):
"""
:type temperatures: List[int]
:rtype: List[int]
"""
temp=[0]
output=[0]*len(temperatures)
for i in range(1,len(temperatures)):
while len(temp):
#使用for循环会超时
#for _ in range(len(temp)):
if temperatures[i]>temperatures[temp[-1]]:
output[temp[-1]]=i-temp[-1]
temp.pop()
else:
break
temp.append(i)
return output
2.中庸行者行走最大步数,使用dfs
3.使用拓扑排序小顶堆
