现在给你m个字符串,对于每个字符串,求中有多少个串是t的单匹配串但不是t的双匹配串。
3,["abc", "bbc", "cbd"],3,["abc","cad","bac"]
[0,1,1]
对于字符串"abc"。没有满足条件的单匹配串字符串“cad"有满足条件的串: "cbd" ,第一个位置都是c,第三个位置都是d,是单匹配串,但是第二个位置不同,不是双匹配串字符串"bac"有满足条件的串: "bbc" ,第一个位置都是b,第三个位置都是c,是单匹配串,但是第二个位置不同,不是双匹配串
class Solution: def solve(self, n, s, m, t): # write code here res = [] for it in t: temp_it = self.get_single_str(it) check_len = len(temp_it) tStr_len = len(it) temp = [self.get_single_str(i)[:check_len] for i in s if (i[:tStr_len] != it if tStr_len > 1 else True) and i[0] == it[0]] res.append(temp.count(temp_it)) return res def get_single_str(self, s: str): return ''.join([s[i] for i in range(len(s)) if i % 2 == 0])