파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 7. 28. 23:45

https://leetcode.com/problems/valid-anagram/

 

Valid Anagram - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

dictionary 개념으로 푼 문제. 역시 Easy는 풀만해..

class Solution:
    def isAnagram(self, s: str, t: str) -> bool:
        l = len(s)
        if l != len(t):
            return False
        ar = [0 for _ in range(26)]
        for i in range(l):
            ar[ord(s[i])-ord('a')] += 1
            ar[ord(t[i])-ord('a')] -= 1
            
        for i in range(26):
            if ar[i]:
                return False
        
        return True
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.07.30
Today's Challenge  (0) 2022.07.29
Today's Challenge  (0) 2022.07.27
Today's Challenge  (0) 2022.07.26
Today's Challenge  (0) 2022.07.25
Comments