Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion valid-anagram/devyejin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from collections import Counter
class Solution(object):
def isAnagram(self, s, t):
return Counter(s) == Counter(t)
# return Counter(s) == Counter(t)

# str에서 제공하는 count 함수 활용
if len(s) != len(t):
return False
for i in set(s):
if s.count(i) != t.count(i):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set + count()라는 아이디어는 이해하기 쉽지만 count()는 문자열 전체를 순회하기 때문에 비효율적입니다. Counter나 정렬 방식 고려해보시길 바랍니다.

return False
return True