首页 > 编程语言 > 详细

187. Repeated DNA Sequences Leetcode Python

时间:2015-03-16 12:57:36      阅读:250      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!