본문 바로가기
python-algorithm

leetcode 290. Word Pattern

by 무적김두칠 2022. 3. 17.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution:
    def wordPattern(self, pattern: str, s: str-> bool:
        s=list(s.split())
        checkList=[]
        checkPattern=[]
        ans=''
        ansPattern=''
        for i in s:
            if i in checkList :
                pass
            else:
                checkList.append(i)
            ans += chr(checkList.index(i) + 97)
        for i in pattern:
            if i in checkPattern :
                pass
            else:
                checkPattern.append(i)
            ansPattern += chr(checkPattern.index(i) + 97)
        if ansPattern==ans: return True
        elsereturn False
cs
반응형

댓글