2019年3月14日 890. Find and Replace Pattern

简单的字符串判断,水题开启新一天。

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
posted @ 2019-03-14 09:27  miuc  阅读(105)  评论(0编辑  收藏  举报