890. 查找和替换模式

890. 查找和替换模式

写点笔记吧

解题思路:判断pattern和word中第i个字母所在的位置是否相同

class Solution:
def findAndReplacePattern(self, words: List[str], pattern: str) -> List[str]:
def check(word, pattern):
for i in range(len(word)):
if word.index(word[i]) != pattern.index(pattern[i]):
return False
return True
res=[]
for i in range(len(words)):
if check(words[i], pattern):
res.append(words[i])
return res

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×