Re: [闲聊] 每日leetcode

楼主: DJYOMIYAHINA (通通打死)   2024-10-25 23:27:47
很好
你很脑残吗
敢这样用sort
我死也不会放过你
我给你一个选择
1. 我把你送去喝oin的水水
要是敢在这边用sort
你就别怪我不客气了
def removeSubfolders(self, folder: List[str]) -> List[str]:
class Node:
def __init__(self):
self.child = {}
self.isFolder = False
root = Node()
# build Trie
for path in folder:
folders = path.split('/')[1:]
cur = root
for f in folders:
if f in cur.child:
cur = cur.child[f]
else:
cur.child[f] = Node()
cur = cur.child[f]
cur.isFolder = True
# inference
ans = []
def dfs(cur_path, root):
if root.isFolder == True:
ans.append(cur_path)
return
for folder, node in root.child.items():
next_path = cur_path + f"/{folder}"
dfs(next_path, node)
dfs("", root)
return ans
作者: oin1104 (是oin的说)   2024-10-25 23:36:00
好 sustainer 喝我水水
作者: Sougou (搜狗)   2024-10-25 23:39:00
蜜汁
作者: sixB (6B)   2024-10-25 23:39:00
sort的复杂度nlognㄟ

Links booklink

Contact Us: admin [ a t ] ucptt.com