1657. 确定两个字符串是否接近
题目链接:1657. 确定两个字符串是否接近
代码如下:
class Solution
{
public:bool closeStrings(string word1, string word2) {if(word1.size()!=word2.size()) {return false;}vector<int> word1_cnt(26,0);for(char c:word1) {word1_cnt[c-'a']++;}vector<int> word2_cnt(26,0);for(char c:word2) {word2_cnt[c-'a']++;}for(int i=0;i<26;i++){if((word1_cnt[i]==0)!=(word2_cnt[i]==0)) {return false;}}sort(word1_cnt.begin(),word1_cnt.end());sort(word2_cnt.begin(),word2_cnt.end());return word1_cnt==word2_cnt;}
};