class Solution {
public:
bool closeStrings(string word1, string word2) {
vector<int> count1(26),count2(26);
for(char c : word1){
count1[c-'a']++;
}
for(char c:word2){
count2[c-'a']++;
}
// 出现的字符相同
for(int i=0;i<26;i++){
if(count1[i]>0 && count2[i]==0||count1[i]==0 && count1[i]>0)
return false;
}
//字符排序后也相同
sort(count1.begin(),count1.end());
sort(count2.begin(),count2.end());
return count1==count2;
}
};