Skip to content

Commit a714949

Browse files
authored
Update 208-Implement-Trie.rb
Revised to remove unnecessary last_idx
1 parent c1f1d5e commit a714949

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

ruby/208-Implement-Trie.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ def initialize
77

88
def insert(word)
99
curr = @root
10-
last_idx = word.length - 1
11-
word.each_char.with_index do |char, idx|
10+
word.each_char do |char|
1211
curr[char] ||= {}
1312
curr = curr[char]
14-
curr[END_OF_WORD] = true if last_idx == idx
1513
end
14+
curr[END_OF_WORD] = true
1615
nil
1716
end
1817

0 commit comments

Comments
 (0)