leetcode 187. Repeated DNA Sequences

题目链接:leetcode

思路,使用字典存储计数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution(object):
def findRepeatedDnaSequences(self, s):
"""
:type s: str
:rtype: List[str]
"""
if len(s) <=10:return []
d = {}
for i in range(0,len(s)-9):
tmp = s[i:i+10]
if tmp in d:
d[tmp] += 1
else:
d[tmp] = 1
res = []
for key in d.keys():
if d[key] >= 2:
res.append(key)
return res