All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 28, 2024
Last updated : June 28, 2024
Related Topics : Array, String, Depth-First Search, Trie
Acceptance Rate : 66.005 %
class Solution:
def removeSubfolders(self, folder: List[str]) -> List[str]:
trie = {}
folder.sort()
output = []
for f in folder :
path = f.split('/')[1:]
curr = trie
add = False
for c in path :
if c not in curr :
curr[c] = {}
add = True
if False in curr :
break
curr = curr[c]
if add and False not in curr:
output.append(f)
curr[False] = True
return output