0588. Design In-Memory File System
https://leetcode.com/problems/design-in-memory-file-system
Description
Design a data structure that simulates an in-memory file system.
Implement the FileSystem class:
FileSystem()
Initializes the object of the system.List<String> ls(String path)
If
path
is a file path, returns a list that only contains this file's name.If
path
is a directory path, returns the list of file and directory names in this directory. The answer should in lexicographic order.
void mkdir(String path)
Makes a new directory according to the givenpath
. The given directory path does not exist. If the middle directories in the path do not exist, you should create them as well.void addContentToFile(String filePath, String content)
If
filePath
does not exist, creates that file containing givencontent
.If
filePath
already exists, appends the givencontent
to original content.
String readContentFromFile(String filePath)
Returns the content in the file atfilePath
.
Example 1:
Constraints:
1 <= path.length, filePath.length <= 100
path
andfilePath
are absolute paths which begin with'/'
and do not end with'/'
except that the path is just"/"
.You can assume that all directory names and file names only contain lowercase letters, and the same names will not exist in the same directory.
You can assume that all operations will be passed valid parameters, and users will not attempt to retrieve file content or list a directory or file that does not exist.
1 <= content.length <= 50
At most
300
calls will be made tols
,mkdir
,addContentToFile
, andreadContentFromFile
.
ac
Last updated