Skip to content

Commit 290d5f2

Browse files
authored
Update replace-words.cpp
1 parent d654990 commit 290d5f2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

C++/replace-words.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ class Solution {
1010
trie.Insert(s);
1111
}
1212
auto curr = ≜
13-
for (int i = 0; i < sentence.length(); ++i) {
14-
if (sentence[i] == ' ' || !curr || !curr->isString) {
15-
result += sentence[i];
13+
for (const auto& c : sentence) {
14+
if (c == ' ' || !curr || !curr->isString) {
15+
result += c;
1616
}
17-
if (sentence[i] == ' ') {
17+
if (c == ' ') {
1818
curr = &trie;
1919
} else if (curr && !curr->isString) {
20-
curr = curr->leaves[sentence[i]];
20+
curr = curr->leaves[c];
2121
}
2222
}
2323
return result;

0 commit comments

Comments
 (0)