Given, Strings s and T, write a function to determine if it is a anagram of s.
For example,
s = "Anagram", t = "Nagaram", return true.
s = "Rat", t = "Car", return false.
Note:
Assume the string contains only lowercase alphabets.
Topic Meaning:
Given two strings s and T, determine if the string T is obtained by the string s adjusted position. (Note is not a palindrome string)
Problem Solving Ideas:
The number of occurrences of a character in each string is recorded, and the number of occurrences of the string T is equal if it is obtained by the string s adjusted position.
Source:
1 classSolution {2 Public:3 BOOLIsanagram (stringSstringt) {4 if(S.size ()!=t.size ())return false;5map<Char,int>CNT;6 for(inti =0; I < s.size (); + + i) cnt[s[i]]++;7 for(inti =0; I < t.size (); + + i) cnt[t[i]]--;8 for(map<Char,int>::iterator iter = Cnt.begin (); Iter!=cnt.end (); ++ITER) {9 if(iter->second!=0)return false;Ten } One return true; A } -};
Leetcode Valid Anagram