Skip to content

Commit f55d5eb

Browse files
committed
[LeetCode Sync] Runtime - 35 ms (19.72%), Memory - 28.8 MB (76.73%)
1 parent acec21f commit f55d5eb

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<p>The <strong>DNA sequence</strong> is composed of a series of nucleotides abbreviated as <code>&#39;A&#39;</code>, <code>&#39;C&#39;</code>, <code>&#39;G&#39;</code>, and <code>&#39;T&#39;</code>.</p>
2+
3+
<ul>
4+
<li>For example, <code>&quot;ACGAATTCCG&quot;</code> is a <strong>DNA sequence</strong>.</li>
5+
</ul>
6+
7+
<p>When studying <strong>DNA</strong>, it is useful to identify repeated sequences within the DNA.</p>
8+
9+
<p>Given a string <code>s</code> that represents a <strong>DNA sequence</strong>, return all the <strong><code>10</code>-letter-long</strong> sequences (substrings) that occur more than once in a DNA molecule. You may return the answer in <strong>any order</strong>.</p>
10+
11+
<p>&nbsp;</p>
12+
<p><strong class="example">Example 1:</strong></p>
13+
<pre><strong>Input:</strong> s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"
14+
<strong>Output:</strong> ["AAAAACCCCC","CCCCCAAAAA"]
15+
</pre><p><strong class="example">Example 2:</strong></p>
16+
<pre><strong>Input:</strong> s = "AAAAAAAAAAAAA"
17+
<strong>Output:</strong> ["AAAAAAAAAA"]
18+
</pre>
19+
<p>&nbsp;</p>
20+
<p><strong>Constraints:</strong></p>
21+
22+
<ul>
23+
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
24+
<li><code>s[i]</code> is either <code>&#39;A&#39;</code>, <code>&#39;C&#39;</code>, <code>&#39;G&#39;</code>, or <code>&#39;T&#39;</code>.</li>
25+
</ul>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def findRepeatedDnaSequences(self, s: str) -> List[str]:
3+
# This is the promary use case of Rabin-Karp?
4+
count = Counter()
5+
result = []
6+
for i in range(len(s) - 9): # len(s) - 10 + 1
7+
tmp = s[i:i + 10]
8+
count[tmp] += 1
9+
if count[tmp] == 2:
10+
result.append(tmp)
11+
12+
return result

0 commit comments

Comments
 (0)