来源:
B站,北大陈斌老师的《数据结构和算法》
def anagramSolution1(s1,s2):
alist=list(s2) #复制s2到列表
pos1=0
stillOK=True
while pos1<len(s1) and stillOK: #循环s1的每个字符
pos2=0
found=False
while pos2<len(alist) and not found:
if s1[pos1]==alist[pos2]: #在s2逐个对比
found=True
else:
pos2=pos2+1
if found:
alist[pos2]=None #找到,打勾
else:
stillOK=False #未找到,失败
pos1=pos1+1
return stillOK
print(anagramSolution1("python","typhon"))