## 题目描述

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.

What if the inputs contain unicode characters? How would you adapt your solution to such case?

## 解法一

### Python

``````class Solution:
def isAnagram(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
if len(s) != len(t):
return False
counts = [0] * 26
for item in s:
counts[ord(item) - ord('a')] += 1
for item in t:
counts[ord(item) - ord('a')] -= 1
return all(count == 0 for count in counts)``````

### Java

``````public class Solution {
public boolean isAnagram(String s, String t) {
if (s.length() != t.length()) {
return false;
}
int[] counts = new int[26];
for (char item : s.toCharArray()) {
counts[item - 'a']++;
}
for (char item : t.toCharArray()) {
counts[item - 'a']--;
}
for (int count : counts) {
if (count != 0) {
return false;
}
}
return true;
}
}``````

### C++

``````class Solution {
public:
bool isAnagram(string s, string t) {
if (s.length() != t.length()) {
return false;
}
vector<int> counts(26, 0);
for (auto item : s) {
counts[item - 'a']++;
}
for (char item : t) {
counts[item - 'a']--;
}
for (auto count : counts) {
if (count != 0) {
return false;
}
}
return true;
}
};``````