File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments