zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    Delete Them
    Toda 2
    JQuery案例:购物车加减
    JQuery案例:折叠菜单
    JQuery案例:暖心小广告
    JQuery案例:左右选
    JQuery动画
    JQuery切换事件
    JQuery文档操作
    JQuery选择器
  • 原文地址:https://www.cnblogs.com/zle1992/p/9172696.html
Copyright © 2011-2022 走看看