187. Repeated DNA Sequences Leetcode Python

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 hashingclass Solution:# @param s, a string# @return a list of stringsdef findRepeatedDnaSequences(self, s):dict={}for i in range(len(s)-9):key=s[i:i+10]if key not in dict:dict[key]=1else:dict[key]+=1res=[]for elem in dict:if dict[elem]>1:res.append(elem)return res

,总有一天,我会丢下我所有的疲倦和理想,

187. Repeated DNA Sequences Leetcode Python

相关文章:

你感兴趣的文章:

标签云: