Skip to content

Latest commit

 

History

History
53 lines (38 loc) · 1.25 KB

_1233. Remove Sub-Folders from the Filesystem.md

File metadata and controls

53 lines (38 loc) · 1.25 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 28, 2024

Last updated : June 28, 2024


Related Topics : Array, String, Depth-First Search, Trie

Acceptance Rate : 66.005 %


Solutions

Python

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