Talentd
FleetCode

242. Valid Anagram

Easy68.5% acceptance40 companies

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

Example 1:

Input: s = "anagram", t = "nagaram"

Output: true

Example 2:

Input: s = "rat", t = "car"

Output: false

Constraints:

  • 1 <= s.length, t.length <= 5 * 104
  • s and t consist of lowercase English letters.

Follow up: What if the inputs contain Unicode characters? How would you adapt your solution to such a case?

12:01
Still stuck?Read 4 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def isAnagram(self, s: str, t: str) -> bool:
3
Starter codePython 3Spaces: 4
Examples
Input
"anagram"
"nagaram"
Input
"rat"
"car"
Your code is saved on this device.Solution