Given two strings s and t, return true if t is an anagram of s, and false otherwise.
Example 1
Input: s = "anagram", t = "nagaram"
Output: true
Example 2
Input: s = "rat", t = "car"
Output: false
1 <= s.length, t.length <= 5*10^4s and t consist of lowercase English letters.Count character frequencies with an array of size 26, or use a hash map.
public boolean isAnagram(String s, String t) {
if (s.length() != t.length()) return false;
int[] count = new int[26];
for (char c : s.toCharArray()) count[c - 'a']++;
for (char c : t.toCharArray()) count[c - 'a']--;
for (int v : count) if (v != 0) return false;
return true;
}Time: O(n) · Space: O(1)