華為算法崗筆試2024屆秋招
1.力扣739.每日溫度,使用單調(diào)棧,使用for循環(huán)不知道為什么會(huì)超時(shí),使用while不會(huì)(看看有沒(méi)有大佬知道為啥)
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)會(huì)超時(shí) #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.使用拓?fù)渑判蛐№敹?/p>