242. Valid Anagram
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
# t 가 s의 anagram 이면 return True
# An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, using all the original letters exactly once.
# 문자와 각 문자의 개수가 같으면 anagram
def getStrCountChar(strs):
countChar = {}
for s in strs:
if s not in countChar:
countChar[s]=1
else:
countChar[s]+=1
countChar = dict(sorted(countChar.items()))
return "".join([f"{k}#{v}_" for k, v in countChar.items()])
# print(getStrCountChar(s))
# print(getStrCountChar(t))
return getStrCountChar(s) == getStrCountChar(t)
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
# anagram 이 되려면, 문자 종류와 개수까지 같으면
return Counter(s) == Counter(t)