文章目录
-
- 原题题目
- 代码实现(首刷自解 暴力哈希表算法 C++)
原题题目
代码实现(首刷自解 暴力哈希表算法 C++)
class FileSystem {
public:unordered_map<string,int> map;FileSystem() {
}bool createPath(string path, int value) {
int pos = path.size() - 1;while(path[pos] != '/') --pos;if(map.find(path) != map.end() || pos && map.find(path.substr(0,pos)) == map.end()) return false;map[path] = value;return true; }int get(string path) {
return map.find(path) == map.end() ? -1 : map[path];}
};/*** Your FileSystem object will be instantiated and called as such:* FileSystem* obj = new FileSystem();* bool param_1 = obj->createPath(path,value);* int param_2 = obj->get(path);*/