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
else: return False
|
cs |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 1051. Height Checker (0) | 2022.03.21 |
---|---|
leetcode 1351. Count Negative Numbers in a Sorted Matrix (0) | 2022.03.20 |
leetcode 1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence (0) | 2022.03.17 |
leetcode 2185. Counting Words With a Given Prefix (0) | 2022.03.17 |
leetcode 557. Reverse Words in a String III (0) | 2022.03.17 |
댓글