華為算法崗筆試2024屆秋招
1.力扣739.每日溫度,使用單調(diào)棧,使用for循環(huán)不知道為什么會超時,使用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循環(huán)會超時 #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.中庸行者行走最大步數(shù),使用dfs
3.使用拓撲排序小頂堆