• 187. Repeated DNA Sequences(建立词典,遍历一遍 o(n))




    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:

    Input: s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"
    
    Output: ["AAAAACCCCC", "CCCCCAAAAA"]

     1 class Solution:
     2     def findRepeatedDnaSequences(self, s):
     3         """
     4         :type s: str
     5         :rtype: List[str]
     6         """
     7         d ={}
     8         for i in range(len(s)-9):
     9             if s[i:i+10] not in  d:
    10                 d[s[i:i+10]]= 1
    11             else:
    12                 d[s[i:i+10]]+= 1
    13         res =[]
    14         for i in d:
    15             if d[i]>1:
    16                 res.append(i)
    17         return res
  • 相关阅读:
    [openjudge] 2797最短前缀 Trie
    [poj]1050 To the Max dp
    [openjudge] 1455:An Easy Problem 贪心
    [poj] Catch That Cow--bfs
    = =
    dinic算法实现
    Dinic
    走进链式前向星的秘密
    树链剖分前传
    树链剖分
  • 原文地址:https://www.cnblogs.com/zle1992/p/9172696.html
Copyright © 2020-2023  润新知