@@ -30,19 +30,19 @@ func contains(word: String) -> Bool {
30
30
// 1
31
31
var currentNode = root
32
32
33
- // 2
33
+ // 2
34
34
var characters = Array (word.lowercased ().characters )
35
35
var currentIndex = 0
36
36
37
- // 3
37
+ // 3
38
38
while currentIndex < characters.count ,
39
39
let child = currentNode.children [character[currentIndex]] {
40
40
41
41
currentNode = child
42
42
currentIndex += 1
43
43
}
44
44
45
- // 4
45
+ // 4
46
46
if currentIndex == characters.count && currentNode.isTerminating {
47
47
return true
48
48
} else {
@@ -69,15 +69,15 @@ func insert(word: String) {
69
69
// 1
70
70
var currentNode = root
71
71
72
- // 2
72
+ // 2
73
73
var characters = Array (word.lowercased ().characters )
74
74
var currentIndex = 0
75
75
76
- // 3
76
+ // 3
77
77
while currentIndex < characters.count {
78
78
let character = characters[currentIndex]
79
79
80
- // 4
80
+ // 4
81
81
if let child = currentNode.children[character] {
82
82
currentNode = child
83
83
} else {
@@ -87,7 +87,7 @@ func insert(word: String) {
87
87
88
88
currentIndex += 1
89
89
90
- // 5
90
+ // 5
91
91
if currentIndex == characters.count {
92
92
currentNode.isTerminating = true
93
93
}
@@ -111,22 +111,22 @@ If you'd like to remove "Apple", you'll need to take care to leave the "App" cha
111
111
func remove (word : String ) {
112
112
guard ! word.isEmpty else { return }
113
113
114
- // 1
114
+ // 1
115
115
var currentNode = root
116
116
117
- // 2
117
+ // 2
118
118
var characters = Array (word.lowercased ().characters )
119
119
var currentIndex = 0
120
120
121
- // 3
121
+ // 3
122
122
while currentIndex < characters.count {
123
123
let character = characters[currentIndex]
124
124
guard let child = currentNode.children[character] else { return }
125
125
currentNode = child
126
126
currentIndex += 1
127
127
}
128
128
129
- // 4
129
+ // 4
130
130
if currentNode.children.count > 0 {
131
131
currentNode.isTerminating = false
132
132
} else {
0 commit comments