Skip to content
BASA DSA

Valid Anagram

EasyArrays & Hashing

Return whether s and t contain exactly the same multiset of letters.

Example 1

Input
s = "silent"
t = "listen"
Output
true

Explanation

Both words contain one each of e, i, l, n, s and t; their order does not change the counts.

Example 2

Input
s = "abb"
t = "aba"
Output
false

Explanation

abb has two b letters while aba has two a letters; equal lengths alone are insufficient.

Example 3

Input
s = ""
t = ""
Output
true

Explanation

Two empty strings have the same zero count for every letter.

Constraints

  • 0 <= string lengths <= 50000
  • Strings contain lowercase English letters

Function contractisAnagramArguments: json, json
Loading draft…
SolutionRuns on your device
Loading draft…