String - Medium
class Solution:
def findAndReplacePattern(self, words: List[str], pattern: str) -> List[str]:
answer = []
for i in range(len(words)):
dic = {}
change = ''
check = []
for j in range(len(words[i])):
letter = words[i][j]
if (letter not in dic) and (check.count(pattern[j]) == 0):
dic[letter] = pattern[j]
check.append(pattern[j])
change += pattern[j]
elif letter not in dic and check.count(pattern[j]) != 0:
change += letter
elif letter in dic:
change += dic[letter]
if change == pattern:
answer.append(words[i])
return answer