LeetCode--Valid Anagram
题目:
Given two strings s and t, write a function to determine if t is an anagram of s.
For example,
s = "anagram", t = "nagaram", return true.
s = "rat", t = "car", return false.
Note:
You may assume the string contains only lowercase alphabets.
bool isAnagram(string s, string t) { unordered_map<char, int> strS; unordered_map<char, int> strT; for(int i = 0; i < s.length(); ++i) { strS[s[i]]++; } for(int i = 0; i < t.length(); ++i) { strT[t[i]]++; } if(strS == strT) return true; else return false; }用unordered_map分别统计每个字母,再比较