b站编程题2——点击视频算法题
n = 5 d = {'33956':['27538','84925'],'79731':['91415','25288'],'25288':['33956']} def findmax(d): res = [] visited = [] for x in d: if x in visited: continue visited.append(x) tem = d[x].copy() rt = 0 while tem: print(tem) p = tem.pop(0) rt += 1 visited.append(p) if p in d: tem += d[p] res.append([x,rt]) res = sorted(res,key=lambda x:x[1])[::-1] return res[0][0]
# 菜鸡代码,大佬勿喷