THE
problem
solution
Code
class Solution {
public:
bool isAnagram(string s, string t) {
unordered_map<char,int> numone, numtwo;
for(char a: s){
numone[a]++;
}
for(char a: t){
numtwo[a]++;
}
if(numone.size()<numtwo.size()){
unordered_map<char,int> temp = numone;
numone = numtwo;
numtwo = temp;
}
for(unordered_map<char,int>::iterator i = numone.begin();i!=numtwo.end();i++){
if(numone[(*i).first] == numtwo[(*i).first]){
continue;
}
else return false;
}
return true;
}
};
Summary and reflection
- Pay attention to exchange issues.