-
Notifications
You must be signed in to change notification settings - Fork 0
/
18-12-22.cpp
31 lines (27 loc) · 860 Bytes
/
18-12-22.cpp
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 similarPairs(vector<string>& words) {
int count=0;
for(int i=0;i<words.size();i++){
vector<int>mapping1(26,0);
for(auto b : words[i]){
mapping1[b-'a']++;
}
for(int j=i+1;j<words.size();j++){
vector<int>mapping2(26,0);
for(auto k:words[j]){
mapping2[k-'a']++;
}
bool equal=true;
for(int k=0;k<mapping1.size();k++){
if((mapping1[k]!=0 && mapping2[k]==0) || (mapping1[k]==0 && mapping2[k]!=0) ){
equal=false;
break;
}
}
if(equal) count++;
}
}
return count;
}
};