[Q] [Medium]
Given two strings s and t, return true if t is an anagram of s, and false otherwise.
- 일단 문제가 짧아서 좋았다.
- 문제가 짧으니까 잘 풀리는 것 같기도..?
- count(i) 함수 써서 해당 '문자열' 의 개수를 value 로 넣어주니 쉽게 풀렸다.
# Answer
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
# 길이 안 맞으면 False
if len(s) != len(t):
return False
s_dict = dict()
t_dict = dict()
for i in s:
s_dict[i] = s.count(i)
for j in t:
t_dict[j] = t.count(j)
if s_dict == t_dict:
return True
return False
'Algorithm > Leetcode' 카테고리의 다른 글
[Top Interview 150 - Hashmap] 219. Contains Duplicate II (1) | 2024.10.12 |
---|---|
[Top Interview 150 - Hashmap] 49. Group Anagrams (0) | 2024.10.12 |
[Top Interview 150 - Hashmap] 290. Word Pattern (0) | 2024.10.12 |
[Top Interview 150 - Hashmap] 205. Isomorphic Strings (0) | 2024.10.12 |
[Top Interview 150 - Hashmap] 383. Ransom Note (0) | 2024.10.12 |