Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ec03cc0

Browse files
D. J.:
- Added the leetcode problem and solution for 187
1 parent e3313df commit ec03cc0

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
- [169 Majority Element](https://leetcode.com/problems/majority-element/description/)
183183
- [172 Factorial Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes/description/)
184184
- [173 Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator/description/)
185+
- [187 Repeated DNA Sequences](https://leetcode.com/problems/repeated-dna-sequences/description/)
185186
- [188 Best Time to Buy and Sell Stock IV](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/description/)
186187
- [189 Rotate Array](https://leetcode.com/problems/rotate-array/description/)
187188
- [190 Reverse Bits](https://leetcode.com/problems/reverse-bits/description/)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import collections
2+
from typing import List
3+
4+
5+
class Solution:
6+
"""Base class for all LeetCode Problems."""
7+
8+
def findRepeatedDnaSequences(self, s: str) -> List[str]:
9+
"""
10+
The DNA sequence is composed of a series of nucleotides abbreviated
11+
as 'A', 'C', 'G', and 'T'.
12+
13+
For example, "ACGAATTCCG" is a DNA sequence.
14+
When studying DNA, it is useful to identify repeated sequences within the DNA.
15+
16+
Given a string s that represents a DNA sequence, return all the 10-letter-long
17+
sequences (substrings) that occur more than once in a DNA molecule. You may
18+
return the answer in any order.
19+
"""
20+
count = collections.defaultdict(int)
21+
for i in range(len(s) - 9):
22+
sequence = s[i : i + 10]
23+
count[sequence] += 1
24+
return list(filter(lambda key: count[key] >= 2, count.keys()))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from typing import List
2+
3+
import pytest
4+
5+
from awesome_python_leetcode._187_repeated_dna_sequences import Solution
6+
7+
8+
@pytest.mark.parametrize(
9+
argnames=["s", "expected"],
10+
argvalues=[
11+
("AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT", ["AAAAACCCCC", "CCCCCAAAAA"]),
12+
("AAAAAAAAAAAAA", ["AAAAAAAAAA"]),
13+
],
14+
)
15+
def test_func(s: str, expected: List[str]):
16+
"""Tests the solution of a LeetCode problem."""
17+
dna_sequences = Solution().findRepeatedDnaSequences(s)
18+
assert dna_sequences == expected

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /