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"].
this Problem can be solve with O(n) time and O(n) space with hashing
class Solution: # @param s, a string # @return a list of strings def findRepeatedDnaSequences(self, s): dict={} for i in range(len(s)-9): key=s[i:i+10] if key not in dict: dict[key]=1 else: dict[key]+=1 res=[] for elem in dict: if dict[elem]>1: res.append(elem) return res
187. Repeated DNA Sequences Leetcode Python
原文地址:http://blog.csdn.net/hyperbolechi/article/details/44302991