简单的字符串判断,水题开启新一天。
class Solution(object): def findAndReplacePattern(self, words, pattern): """ :type words: List[str] :type pattern: str :rtype: List[str] """ ret = [] replace_map = {} replaced = set() for word in words: replace_map = {} replaced = set() finded = True for i, c in enumerate(pattern): if c not in replace_map and word[i] not in replaced: replaced.add(word[i]) replace_map[c] = word[i] else: if c not in replace_map or word[i] != replace_map[c]: finded = False break if finded: ret.append(word) return ret