Skip to content

Commit 23e61e9

Browse files
authored
Update alien-dictionary.cpp
1 parent c96ad47 commit 23e61e9

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

C++/alien-dictionary.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class Solution {
1414
}
1515
}
1616
for (int i = 1; i < words.size(); ++i) {
17+
if (words[i - 1].length() > words[i].length() &&
18+
words[i - 1].substr(0, words[i].length()) == words[i]) {
19+
return "";
20+
}
1721
findEdges(words[i - 1], words[i], &in_degree, &out_degree);
1822
}
1923
for (const auto& node : nodes) {

0 commit comments

Comments
 (0)