MCPcopy Create free account
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / anagramSolution1

Method anagramSolution1

AnagramDetection.py:5–21  ·  view source on GitHub ↗
(self, s1, s2)

Source from the content-addressed store, hash-verified

3 # 对字符串对应的两个list进行排序
4 # 依次比较字符是否匹配
5 def anagramSolution1(self, s1, s2):
6 alist1 = list(s1)
7 alist2 = list(s2)
8
9 alist1.sort()
10 alist2.sort()
11
12 pos = 0
13 matches = True
14
15 while pos < len(s1) and matches:
16 if alist1[pos] == alist2[pos]:
17 pos = pos + 1
18 else:
19 matches = False
20
21 return matches
22
23 # 首先生成两个26个字母的list
24 # 计算每个字母出现的次数并存入到相应的list中

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected