588. Design In-Memory File System

Design an in-memory file system with the following operations:

  • ls(path): If path is a file, return its name. If path is a directory, return all files and directories in it (sorted lexicographically).
  • mkdir(path): Create a directory at path if it doesn't exist (path may have nested directories).
  • addContentToFile(filePath, content): Create a file at filePath with given content if it doesn't exist, otherwise append content.
  • readContentFromFile(filePath): Return the content of the file.
Examples
Input: [["FileSystem","ls","mkdir","addContentToFile","ls","readContentFromFile"],[[],["/"],["/a/b/c"],["/a/b/c/d","hello"],["/"],["/a/b/c/d"]]]
Output: [null,[],null,null,["a"],"hello"]
Hints
Related Problems

588. Design In-Memory File System

Design an in-memory file system with the following operations: