Valid Anagram
EasyArrays & Hashing
Given two strings s and t, return True if t is an anagram of s, and False otherwise.
t is an anagram of s when it uses exactly the same letters with exactly the same counts, just possibly in a different order. Strings of different lengths can never be anagrams.
Follow-up: how would your solution change if the strings could contain arbitrary Unicode characters?
Example 1
- Input:
- s = "finder", t = "friend"
- Output:
- True
- Explanation
- Both strings use d, e, f, i, n and r exactly once, just in a different order.
Example 2
- Input:
- s = "aacc", t = "ccac"
- Output:
- False
- Explanation
shas two a and two c, whilethas one a and three c. The letters match but the counts do not.
Example 3
- Input:
- s = "stone", t = "tones"
- Output:
- True
- Explanation
- Both have one each of e, n, o, s and t.
Constraints
1 <= s.length, t.length <= 5 * 10^4sandtconsist of lowercase English letters