242. 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.
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?
判断一个串的字母打乱顺序后,是否等于另一个串
C++(12ms):
1 class Solution { 2 public: 3 bool isAnagram(string s, string t) { 4 if (s.size() != t.size()) 5 return false ; 6 vector<int> vec(128,0) ; 7 for(char c : s){ 8 vec[c-'a']++ ; 9 } 10 for(char c : t){ 11 if (--vec[c-'a'] < 0) 12 return false ; 13 } 14 return true ; 15 } 16 };