-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (46 loc) · 950 Bytes
/
main.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
func main() {
}
type MagicDictionary struct {
store []string
}
func Constructor() MagicDictionary {
return MagicDictionary{}
}
func (this *MagicDictionary) BuildDict(dictionary []string) {
this.store = append(this.store, dictionary...)
}
func (this *MagicDictionary) Search(searchWord string) bool {
// fmt.Println(searchWord)
for i := 0; i < len(this.store); i++ {
if canChange(this.store[i], searchWord) {
// this.store[i] = "test"
return true
}
}
return false
}
func canChange(str1, str2 string) bool {
if len(str1) != len(str2) {
return false
}
var check bool
for i := 0; i < len(str1); i++ {
if str1[i] != str2[i] {
if check {
return false
}
check = true
}
}
if !check {
return false
}
return true
}
/**
* Your MagicDictionary object will be instantiated and called as such:
* obj := Constructor();
* obj.BuildDict(dictionary);
* param_2 := obj.Search(searchWord);
*/