forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1166.go
More file actions
32 lines (26 loc) · 631 Bytes
/
1166.go
File metadata and controls
32 lines (26 loc) · 631 Bytes
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
31
32
type FileSystem struct {
paths map[string]int
}
func Constructor() FileSystem {
res := new(FileSystem)
res.paths = make(map[string]int)
res.paths[""] = -1
return *res
}
func (this *FileSystem) Create(path string, value int) bool {
parent := path[:strings.LastIndex(path, "/")]
if _, ok := this.paths[parent]; !ok {
return false
}
if _, ok := this.paths[path]; ok {
return false
}
this.paths[path] = value
return true
}
func (this *FileSystem) Get(path string) int {
if _, ok := this.paths[path]; !ok {
return -1;
}
return this.paths[path];
}