The size of unordered map keeps increasing in the last for loop? Why is it so?
class Solution {
public:
bool isAnagram(string s, string t) {
if(s.size() != t.size()){
return false;
}
unordered_map<char,int> sm;
unordered_map<char,int> tm;
for (int i = 0; i<s.size();i++){
sm[s[i]]++;
tm[t[i]]++;
}
for (int j = 0; j<sm.size();j++){
cout << j << endl;
cout << sm.size() <<endl;
if(sm[j] != tm[j]){
cout << sm[j] << endl;
cout << tm[j] << endl;
cout << j << endl;
return false;
}
}
return true;
}
};
I have tried to search online but can't find any relevant answer.