来源:
B站,北大陈斌老师的《数据结构和算法》
def anagramSolution2(s1,s2):
alist1=list(s1) #转为列表
alist2=list(s2)
alist1.sort() #列表排序
alist2.sort()
pos=0
matches=True
while pos<len(s1) and matches:
if alist1[pos]==alist2[pos]: #逐个对比
pos=pos+1
else:
matches=False
return matches
print(anagramSolution2('python','typhon'))