Topic:
" Anagram " " Nagaram " true "rat""car"false Note: The string is assumed to contain only lowercase letters. Increased difficulty: What if the input string contains unicode characters? Can you adapt your solution to this situation?
1, problem-solving ideas:
The subject is relatively simple, the number of 128 characters in the two string is directly counted, and then the comparison quantity is equal.
classSolution { Public: BOOLIsanagram (stringSstringt) {map<Char,int>maps; Map<Char,int>mapt; if(S.size ()! =t.size ()) { return false; } for(inti =0; i < s.size (); + +i) { if(Maps.find (s[i])! =Maps.end ()) {Maps[s[i]]+=1; }Else{Maps[s[i]]=1; } if(Mapt.find (t[i])! =Mapt.end ()) {Mapt[t[i]]+=1; }Else{Mapt[t[i]]=1; } } for(inti =0; i < t.size (); + +i) { if(maps[s[i]]!=Mapt[s[i]]) { return false; } } return true; }};
"Primary algorithm" 15. Valid letter-to-word synonyms