-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepeatedDNA_SW.py
More file actions
33 lines (26 loc) · 835 Bytes
/
repeatedDNA_SW.py
File metadata and controls
33 lines (26 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution(object):
def findRepeatedDnaSequences(self, s):
"""
:type s: str
:rtype: List[str]
"""
# Store what has been seen
seen = set()
# Store what has been repeated
repeated = set()
# left and right pointers
left = 0
right = 10
while right <= len(s):
# the substring to compare
substr = s[left:right]
# if the substring has been seen before, it is repeated
if substr in seen:
repeated.add(substr)
# otherwise add it to what has been seen before
else:
seen.add(substr)
# right and left pointer move forward
right += 1
left += 1
return list(repeated)