파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 7. 29. 23:45

https://leetcode.com/problems/find-and-replace-pattern/

 

Find and Replace Pattern - 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

필터 함수를 활용해서 푸는 방법이 있길래 따라 해 봄.

class Solution:
    def findAndReplacePattern(self, words: List[str], pattern: str) -> List[str]:
        def match(word):
            m1, m2 = {}, {}
            for w, p in zip(word, pattern):
                if w not in m1:
                    m1[w] = p
                if p not in m2:
                    m2[p] = w
                if (m1[w], m2[p]) != (p, w):
                    return False
            return True
        
        return filter(match, words)
반응형

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

Today's Challenge  (0) 2022.07.31
Today's Challenge  (0) 2022.07.30
Today's Challenge  (0) 2022.07.28
Today's Challenge  (0) 2022.07.27
Today's Challenge  (0) 2022.07.26
Comments