← 返回 amazon 的题目列表DirectoryTree Class with Path Addition and Subtree Check
类型:online_judge
amazon
Design a class DirectoryTree to represent a file directory tree where each node can have multiple children and a name property (representing the name of the file or folder) as well as a boolean isFile to distinguish between files and folders. Implement the following functions:
addPath(path: str) -> None: Add a file or folder given its path.
isSubtree(s: DirectoryTree, t: DirectoryTree) -> bool: Determine if the directory tree t is a subtree of the directory tree s.
Constraints:
The path path is in the format /a/b/c, where c can be a file or a folder.
The input will not contain duplicate paths.
Example:
Input:
- addPath("/a/b/c")
- addPath("/a/d")
- isSubtree(s, t)
Output:
- No output
- No output
- True