Problem
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: “ACGAATTCCG”. When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.
Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.
Example:
1 |
|
Explanation
-
If the string has length less than or equal to 10, we return empty result.
-
We can loop through the string, put each 10 characters long string into a set. In the future iteration, check if the set already contains the new 10 character slong string. If contains, then we can add this string into the result set.
-
Finally return a list of the result set.
Solution
1 |
|