242.Valid Anagram
示例 1:
输入: s = "anagram", t = "nagaram"
输出: true
示例 2:
输入: s = "rat", t = "car"
输出: false
说明:
你可以假设字符串只包含小写字母。class Solution {
public:
bool isAnagram(string s, string t) {
int s1[26]={0};
int t1[26]={0};
for(auto c:s)
s1[c-'a']++;
for(auto c:t)
t1[c-'a']++;
for(int i=0;i<26;i++)
if(s1[i]!=t1[i]) return false;
return true;
}
};Last updated