Skip to content

Commit b319003

Browse files
authored
Update longest-word-with-all-prefixes.cpp
1 parent 1154691 commit b319003

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

C++/longest-word-with-all-prefixes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Solution {
3535
vector<TrieNode *> stk = {node};
3636
while (!empty(stk)) {
3737
const auto node = stk.back(); stk.pop_back();
38-
if (node->idx != -1 && (result == -1 || size(words[node->idx]) > size(words[result]))) {
38+
if (result == -1 || size(words[node->idx]) > size(words[result])) {
3939
result = node->idx;
4040
}
4141
for (char c = 'z'; c >= 'a'; --c) {
@@ -84,7 +84,7 @@ class Solution2 {
8484

8585
private:
8686
void dfs(const vector<string>& words, TrieNode *node, int *result) {
87-
if (node->idx != -1 && (*result == -1 || size(words[node->idx]) > size(words[*result]))) {
87+
if (*result == -1 || size(words[node->idx]) > size(words[*result])) {
8888
*result = node->idx;
8989
}
9090
for (char c = 'a'; c <= 'z'; ++c) {

0 commit comments

Comments
 (0)