-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
1166.java
30 lines (25 loc) · 894 Bytes
/
1166.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
__________________________________________________________________________________________________
class FileSystem {
Map<String, Integer> map;
public FileSystem() {
map = new HashMap<>();
map.put("", 0);
}
public boolean create(String path, int value) {
if(map.containsKey(path)){
return false;
}
int pos = path.lastIndexOf("/");
String par = path.substring(0, pos);
if(!map.containsKey(par)){
return false;
}
map.put(path, value);
return true;
}
public int get(String path) {
return map.containsKey(path) ? map.get(path) : -1;
}
}
__________________________________________________________________________________________________
__________________________________________________________________________________________________