其他分享
首页 > 其他分享> > 2019年3月14日 890. Find and Replace Pattern

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

标签:890,map,word,14,finded,Pattern,replace,replaced,pattern
来源: https://www.cnblogs.com/seenthewind/p/10528146.html