Problem Statement
Given two strings
s
andt
, returntrue
ift
is an anagram ofs
, andfalse
otherwise.An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
Example 1:
Input: s = "anagram", t = "nagaram"
Output: true
Example 2:
Input: s = "rat", t = "car"
Output: false
Solution
Python Implementation
from collections import Counter
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
"""
T: O(N) = max(S + T)
S: O(N)
"""
s_mp = Counter(s)
t_mp = Counter(t)
return s_mp == t_mp