首页 > 其他 > 详细

Repeated DNA Sequences

时间:2015-11-01 19:28:25      阅读:269      评论:0      收藏:0      [点我收藏+]

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     }

 

Repeated DNA Sequences

原文:http://www.cnblogs.com/ordili/p/4928351.html

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