We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8314568 commit 1d38742Copy full SHA for 1d38742
C++/design-file-system.cpp
@@ -0,0 +1,28 @@
1
+// Time: create: O(n)
2
+// get: O(n)
3
+// Space: O(n)
4
+
5
+class FileSystem {
6
+public:
7
+ FileSystem() : lookup_({{"", -1}}) {
8
9
+ }
10
11
+ bool create(string path, int value) {
12
+ if (!lookup_.count(path.substr(0, path.find_last_of('/')))) {
13
+ return false;
14
15
+ lookup_[path] = value;
16
+ return true;
17
18
19
+ int get(string path) {
20
+ if (!lookup_.count(path)) {
21
+ return -1;
22
23
+ return lookup_[path];
24
25
26
+private:
27
+ unordered_map<string, int> lookup_;
28
+};
0 commit comments