全部保存起来,去重,OK
字符串匹配
http://www.nowcoder.com/questionTerminal/6e6ad6338289498da79b7afb60e823b3
def solution(): # A = input() # B = input() A = '00010001' B = '??' lenA = len(A) lenB = len(B) res = [] for i in range(lenA-lenB+1): tmp = 0 for j in range(lenB): if B[j] == '?' or B[j] == A[i:i+lenB][j]: tmp += 1 if tmp == lenB: res.append(A[i:i+lenB]) else: break print(len(set(res))) solution()