Loading...
You are given two strings s and t. Determine whether t is an anagram of s, meaning whether t can be formed by rearranging the characters of s, using every character exactly once.
Return true if the two strings contain exactly the same characters with the same frequencies, and false otherwise.
Input: s = "anagram", t = "nagaram"
Output: true
Explanation: Both strings contain three 'a's and one each of 'n', 'g', 'r', and 'm'.
Input: s = "rat", t = "car"
Output: false
Explanation: t contains a 'c', which never appears in s.
s.length, t.length ≤5⋅104s and t consist of lowercase English letters only.Click "Run" to test with sample cases or "Submit" to run all tests.