LeetCode 242. Valid Anagram

개발공부를해보자·2025년 2월 24일

LeetCode

목록 보기
62/95

파이썬 알고리즘 인터뷰 62번(리트코드 242) Valid Anagram
https://leetcode.com/problems/valid-anagram/

나의 풀이1

class Solution:
    def isAnagram(self, s: str, t: str) -> bool:
        if len(s) != len(t):
            return False

        s_count = collections.Counter(s)
        t_count = collections.Counter(t)

        for char in s_count:
            if s_count[char] != t_count[char]:
                return False

        return True
  • 이 풀이가 아래 풀이보다 더 빠르다.

나의 풀이2

class Solution:
    def isAnagram(self, s: str, t: str) -> bool:
        return sorted(s) == sorted(t)
profile
개발 공부하는 30대 비전공자 직장인

0개의 댓글