当前位置:网站首页>leetcode:6097. 替换字符后匹配【set记录 + 相同长度逐一查询】

leetcode:6097. 替换字符后匹配【set记录 + 相同长度逐一查询】

2022-06-12 18:36:00 白速龙王的回眸

在这里插入图片描述

分析

用set记录可替换的
然后就s找到长度和sub相同的
然后逐个看看如果不等的话能不能map过去

ac code

class Solution:
    def matchReplacement(self, s: str, sub: str, mappings: List[List[str]]) -> bool:
        n, m = len(s), len(sub)
        
        mySet = set()
        for x, y in mappings:
            mySet.add((x, y))
            
        #print(myDict)
        for i in range(n - m + 1):
            cankao = s[i: i + m]
            #print(cankao)
            flag = True
            for j in range(m):
                if sub[j] != cankao[j] and (sub[j], cankao[j]) not in mySet:
                    flag = False
                    break
            if flag:
                return True
        
        return False
                
                

总结

简单set

原网站

版权声明
本文为[白速龙王的回眸]所创,转载请带上原文链接,感谢
https://bridge-killer.blog.csdn.net/article/details/125248103