Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bb3b717

Browse files
committedJul 2, 2017
Solution for: repeated DN sequences
1 parent a0ad88d commit bb3b717

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
 
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package leetcode;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashMap;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
public class RepeatedDNASequences {
9+
10+
public static void main(String[] args) {
11+
// TODO Auto-generated method stub
12+
13+
}
14+
15+
public List<String> findRepeatedDnaSequences(String s) {
16+
List<String> list = new ArrayList<>();
17+
if(s.length() < 10) return list;
18+
Map<String, Integer> map = new HashMap<>();
19+
for(int i=0; i< s.length()-9;i++){
20+
String sub= s.substring(i,i+10);
21+
if(map.containsKey(sub)){
22+
map.put(sub, map.get(sub)+1);
23+
}else{
24+
map.put(sub, 1);
25+
}
26+
}
27+
28+
for( String key: map.keySet()){
29+
if(map.get(key)>1)
30+
list.add(key);
31+
}
32+
return list;
33+
34+
}
35+
36+
}

0 commit comments

Comments
 (0)
Please sign in to comment.