Valid Anagram

Medium~15 min

Given two strings s and t, return true if t is an anagram of s, and false otherwise.

An anagram is a word formed by rearranging the letters of another word, using all the original letters exactly once.

Examples

Example 1
Input: s = "anagram", t = "nagaram"
Output: true
Explanation: "nagaram" uses the same letters as "anagram" — each letter appears the same number of times.
Example 2
Input: s = "rat", t = "car"
Output: false
Explanation: "rat" has a 't' but "car" does not. The letter frequencies differ.
Example 3
Input: s = "a", t = "a"
Output: true
Explanation: Single character strings with the same character are anagrams.

Constraints

  • 1 <= s.length, t.length <= 5 * 10^4
  • s and t consist of lowercase English letters
  • Expected time complexity: O(n)
Code
Ctrl+EnterRun|Ctrl+⇧+EnterSubmit
Output

Run your code to see results

Use Cmd+Enter to run