Valid Anagram
Easy · hash map
Given two strings s and t made of lowercase letters, return True if t is an anagram of s, and False otherwise.
Two strings are anagrams when they use exactly the same letters, the same number of times, in any order. Two empty strings count as anagrams of each other.
Examples
Example 1
Input: s = "anagram", t = "nagaram"
Output: True
Both strings have three "a", one "n", one "g", one "r" and one "m".
Example 2
Input: s = "rat", t = "car"
Output: False
The letters differ: "t" is in s but not in t, and "c" is in t but not in s.
Example 3
Input: s = "ab", t = "a"
Output: False
The lengths differ, so the letter counts cannot match.
Constraints
- 0 <= len(s), len(t) <= 10^4
- s and t contain only lowercase English letters.