• 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     }
  • 相关阅读:
    05-浮动/css
    04-选择器/css
    03-样式表/css
    02-html标签&表格&表单
    01-html基础&标签
    vue分页组件重置到首页问题
    VUE通过索引值获取数据不渲染的问题
    常见IE8兼容性问题及解决
    Ajax
    sea.js模块化工具
  • 原文地址:https://www.cnblogs.com/ordili/p/4928351.html
Copyright © 2020-2023  润新知