← 返回 databricks 的题目列表In-Memory File System APIs
类型:online_judge
Design and implement an in-memory file system supporting directories and files. Implement the following APIs:
ls(path) -> List[str]
If path is a directory, return all immediate children names (files and subdirectories) in lexicographical order.
If path is a file, return a list containing only the file name.
mkdir(path): create a directory at path (create intermediate directories if missing).
addContentToFile(filePath, content): append content to a file; create the file if it does not exist.
readContentFromFile(filePath) -> str: return the full content of the file.
Constraints:
Unix-style paths, / is the root.
Names contain lowercase letters only.
Ensure correctness and reasonable time complexity.
Provide at least 5 test sequences with expected outputs.
Example
Input
mkdir /a/b/c
ls /
Output
["a"]