zoukankan      html  css  js  c++  java
  • Repeated DNA Sequences

    1. Title

    Repeated DNA Sequences

    2.   Http address

    https://leetcode.com/problems/repeated-dna-sequences/

    3. The question

    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"].

    4. My code (AC)

     1     //Accept
     2     public static List<String> findRepeatedDNASeq(String s){
     3 
     4         List<String> re = new ArrayList<String>();
     5         Map<String,Integer> dit = new HashMap<String,Integer>();
     6         String key = "";
     7         int value = 0;
     8         if ( s == null || s.length() < 10 )
     9         {
    10             return re;
    11         }
    12 
    13         for(int i = 0 ; i <= s.length() - 10;i++ )
    14         {
    15                 key = s.substring(i,i+10);
    16                 if( dit.containsKey(key) )
    17                 {
    18 //                    i += 10;
    19                     value = dit.get(key);
    20                     if( value == 1 )
    21                     {
    22                         re.add(key);
    23                         dit.put(key,0);
    24                     }
    25 
    26                 }else{
    27                     dit.put(key,1);
    28                 }
    29         }
    30         
    31         return re;
    32     }
  • 相关阅读:
    ES6模块开发+单文件组件
    Vue路由学习
    Vuex学习
    Vue组件
    Vue事件处理
    Git下载前后端代码步骤
    小黑记事本
    简单计算器
    ubuntu的基础命令
    拓扑排序以及求解关键路径
  • 原文地址:https://www.cnblogs.com/ordili/p/4928351.html
Copyright © 2011-2022 走看看