Skip to content

Latest commit

 

History

History
49 lines (39 loc) · 1 KB

187.md

File metadata and controls

49 lines (39 loc) · 1 KB
  1. Repeated DNA Sequences
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.

For example,

Given s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT",

Return:
["AAAAACCCCC", "CCCCCAAAAA"].

my thoughts:

1. hash set to track occurance.

my solution:

**********103ms
class Solution(object):
    def findRepeatedDnaSequences(self, s):
        """
        :type s: str
        :rtype: List[str]
        """
        if len(s) < 11:
            return []
        d = set()
        res = set()
        for i in range(len(s)-9):
            cur = s[i:i+10]
            if cur not in d:
                d.add(cur)
            else:
                res.add(cur)
                
        return list(res)

my comments:


from other ppl's solution:

1. N/A