10588. Design In-Memory File System

Create an in-memory file system supporting the following operations:

  • show: Given a string path, if it leads to a file, return a list containing only the file name. If it leads to a folder, return a list of all files and subfolder names in that folder, sorted in lexicographical order.
  • makeDir: Given a new folder path, create the folder. If any intermediate folders do not exist, create them as well. This method returns nothing.
  • writeFile: Given a file path and content as a string, create the file and set its content. If the file already exists, append the new content to the existing content. This method returns nothing.
  • readFile: Given a file path, return its content as a string.

Examples

Input:
["MemorySystem","show","makeDir","writeFile","show","readFile"]
[[],["/"],["/x/y/z"],["/x/y/z/file1","sample"],["/"],["/x/y/z/file1"]]

Output:
[null,[],null,null,["x"],"sample"]

Explanation:
After creating the folder structure and adding a file with content "sample", listing files at the root gives ["x"], and reading the content at "/x/y/z/file1" returns "sample".

Constraints

  • All file and folder paths are absolute, starting with /, and do not end with / (except "/" itself).
  • All operations are given valid parameters; users will not try to access files or folders that do not exist.
  • File and folder names use only lowercase English letters and are unique within any single folder.
  • Total number of operations will not exceed 12,000.
  • File content size will not exceed 200,000 characters.




Please use Laptop/Desktop or any other large screen to add/edit code.