-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2506.cpp
More file actions
28 lines (27 loc) · 730 Bytes
/
2506.cpp
File metadata and controls
28 lines (27 loc) · 730 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
class Solution {
public:
bool isSimilar(string& s1, string& s2) {
vector<bool> hashS1(26, false);
vector<bool> hashS2(26, false);
for (auto& c : s1) {
hashS1[c - 'a'] = true;
}
for (auto& c : s2) {
hashS2[c - 'a'] = true;
}
for (int i = 0; i < 26; ++i) {
if (hashS1[i] != hashS2[i]) return false;
}
return true;
}
int similarPairs(vector<string>& words) {
int n = words.size();
int cnt = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (isSimilar(words[i], words[j])) cnt++;
}
}
return cnt;
}
};