leetcode187

 1 class Solution:
 2     def findRepeatedDnaSequences(self, s: str) -> 'List[str]':
 3         n = len(s)
 4         if n <= 10:
 5             return []
 6         res = []
 7         bstr = s[:10]
 8         dic = {bstr:1}
 9         i,j = 1,10
10         while j < n:
11             nstr = bstr[1:] + s[j]
12             if nstr not in dic:
13                 dic[nstr] = 1
14             else:
15                 dic[nstr] += 1
16             j += 1
17             bstr = nstr
18         for k,v in dic.items():
19             if v > 1:
20                 res.append(k)
21         return res

猜你喜欢

转载自www.cnblogs.com/asenyang/p/12021802.html