bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1166. Design File System

1166. Design File System

Leetcode Solutions

Dictionary-based Approach for File System

  1. Initialize a dictionary paths to store path-value pairs.
  2. For createPath, first check if the path is valid (not empty or just '/').
  3. Check if the path already exists in paths; if it does, return false.
  4. Extract the parent path and check if it exists in paths (except for the root '/').
  5. If the parent path exists, add the new path to paths with the given value and return true.
  6. For get, check if the path exists in paths; if it does, return the associated value, otherwise return -1.
UML Thumbnail

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...