Skip to content

Commit c68813a

Browse files
authored
Update word-abbreviation.cpp
1 parent 1ef9d3b commit c68813a

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

C++/word-abbreviation.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,10 @@ class Solution {
3737

3838
private:
3939
bool isUnique(const string& prefix, const unordered_set<string>& words) {
40-
int count = 0;
41-
for (const auto& word : words) {
42-
if (!word.compare(0, prefix.length(), prefix)) {
43-
if (++count > 1) {
44-
return false;
45-
}
46-
}
47-
}
48-
return true;
40+
return 1 == count_if(words.begin(), words.end(),
41+
[&prefix](const string& word) {
42+
return !word.compare(0, prefix.length(), prefix);
43+
});
4944
}
5045

5146
string toAbbr(const string& prefix, const string& word) {

0 commit comments

Comments
 (0)