Skip to content

Commit b6ceb68

Browse files
authored
Create design-file-system.py
1 parent 1d38742 commit b6ceb68

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Python/design-file-system.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Time: create: O(n)
2+
# get: O(n)
3+
# Space: O(n)
4+
5+
class FileSystem(object):
6+
7+
def __init__(self):
8+
self.__lookup = {"": -1}
9+
10+
def create(self, path, value):
11+
"""
12+
:type path: str
13+
:type value: int
14+
:rtype: bool
15+
"""
16+
if path[:path.rfind('/')] not in self.__lookup:
17+
return False
18+
self.__lookup[path] = value
19+
return True
20+
21+
def get(self, path):
22+
"""
23+
:type path: str
24+
:rtype: int
25+
"""
26+
if path not in self.__lookup:
27+
return -1
28+
return self.__lookup[path]

0 commit comments

Comments
 (0)