Advertisement
nikunjsoni

1166

Jun 26th, 2021
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. class FileSystem {
  2. private:
  3.   unordered_map<string, int> paths;
  4.    
  5. public:
  6.   bool createPath(const string& path, int value) {
  7.     auto parent = path.substr(0, path.rfind('/'));
  8.     if(!parent.empty() && !paths.count(parent))
  9.       return false;
  10.     return paths.emplace(path, value).second;
  11.   }
  12.    
  13.   int get(const string& path) {
  14.     auto it = paths.find(path);
  15.     if(it == paths.end())
  16.       return -1;
  17.     return it->second;
  18.   }
  19. };
  20.  
  21. /**
  22.  * Your FileSystem object will be instantiated and called as such:
  23.  * FileSystem* obj = new FileSystem();
  24.  * bool param_1 = obj->createPath(path,value);
  25.  * int param_2 = obj->get(path);
  26.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement