-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2135.cpp
More file actions
31 lines (29 loc) · 830 Bytes
/
2135.cpp
File metadata and controls
31 lines (29 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Solution {
public:
int wordCount(vector<string>& startWords, vector<string>& targetWords) {
unordered_set<int> st;
for (auto& word : startWords) {
int mask = 0;
for (auto c : word) {
mask |= (1 << (c - 'a'));
}
st.insert(mask);
}
int count = 0;
for (auto& word : targetWords) {
int mask = 0;
for (auto c : word) {
mask |= (1 << (c - 'a'));
}
for (int i = 0; i < 26; ++i) {
if (mask & (1 << i)) {
if (st.find(mask ^ (1 << i)) != st.end()) {
count++;
break;
}
}
}
}
return count;
}
};