588. Design In-Memory File System

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

  • ls(path): If path is a file, return a list containing only that file's name. If path is a directory, return the names of all files and directories directly inside 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","mkdir","addContentToFile","ls","readContentFromFile","addContentToFile","readContentFromFile","ls"],[[],["/a/d0"],["/a/d0/f0","x0"],["/a"],["/a/d0/f0"],["/a/d0/f0","y"],["/a/d0/f0"],["/a/d0"]]]
Output: [null,null,null,["d0"],"x0",null,"x0y",["f0"]]
Hints

588. Design In-Memory File System

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